利用hidden 属性隐藏显示元素
2017-07-29 本文已影响0人
jia林
html
<button onclick="toggleHidden()">toggle</button>
<table>
<tr>
<th>Name</th>
</tr>
<tr>
<td>Adam</td>
<td>London</td>
</tr>
<tr id="toggle" hidden>
<td>Joe</td>
<td>New</td>
</tr>
<tr>
<td>Anne</td>
<td>Paries</td>
</tr>
</table>
js
<script>
var toggleHidden=function(){
var elem = document.getElementById('toggle');
if(elem.hasAttribute('hidden)){
elem.removeAttribute('hidden')
}else{
elem.setAttribute('hidden','hidden')
}
}
</script>