<body>
<button onclick="toggleHidden()">Toggle</button>
<table>
<tr>
<th>Name</th>
<th>City</th>
</tr>
<tr>
<td>Adam Freeman</td>
<td>London</td>
</tr>
<tr id="toggle" hidden>
<td>Joe Smith</td>
<td>New York</td>
</tr>
<tr>
<td>Anne Jones</td>
<td>Paris</td>
</tr>
</table>
<script>
var toggleHidden = function () {
var elem = document.getElementById("toggle");
if (elem.hasAttribute("hidden")) {
elem.removeAttribute("hidden");
} else {
elem.setAttribute("hidden", "hidden");
}
};
</script>
</body>
html 全局属性hidden 可以设置隐藏某元素
最新推荐文章于 2023-09-05 12:09:46 发布