Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 全选复选框
我有一个 Check All 按钮的以下代码,它将检查我网页上的所有复选框,但它不起作用。函数应该去哪里?因为我尝试将代码放在我的页面上,但它不起作用。
http://jsfiddle.net/KbkZk/1/
对不起大声笑,漫长的一天!
什么代码?通常,您将 JS 放在<head>页面的块中。如果 JS 将处理页面的内容,则需要延迟其执行,直到页面的其余部分加载完毕。在 jquery 中,你可以这样做:
<head>
<script> $(document).ready(function() { ... your code here ... }): </script>
如果您不使用 JS 库,您可以使用以下方法执行几乎相同的操作:
<body onload="myFunction();">
并让 myFunction 进行初始化/设置。