【发布时间】:2015-07-01 05:24:42
【问题描述】:
我正在使用以下代码,但它不起作用。告诉我是否有任何建议。我希望在加载页面时取消选中所有复选框。我有以下代码,但它不起作用:
window.onload = function abc() {
document.getElementsByTagName('input')[0].focus();
}
<tr>
<td>
<input type="checkbox" ID="cb1" value="29500" onclick="if(this.checked){ cbcheck(this) } else { cbuncheck(this)}" /> Laptop
</td>
<td>
<a href="#" id="a1" onmouseover="showimage('a1','laptop1');" >Show Image</a>
<img src="Images/laptop.jpg" id="laptop1" alt="" style="display:none; width:150px; height:150px;" onmouseout="hideimage('a1','laptop1');" class="right"/>
</td>
</tr>
<tr>
<td>
<input type="checkbox" ID="cb2" value="10500" onclick="if(this.checked){ cbcheck(this) } else { cbuncheck(this)}" /> Mobile
</td>
<td>
<a href="#" id="a2" onmouseover="showimage('a2','mobile1');" >Show Image</a>
<img src="Images/mobile.jpg" id="mobile1" alt="" style="display:none; width:150px; height:150px;" onmouseout="hideimage('a2','mobile1');" />
</td>
</tr>
【问题讨论】:
-
你为什么不用 jQuery?
-
A.如果您不将它们设置为选中,则默认情况下它们将处于未选中状态。 (您是否害怕 asp.net viewstate 或类似的东西?) B.Focus 无济于事。将
checked设置为假。 This 也应该有帮助。 -
@techie_28,也许是因为你并不总是需要使用 jQuery :)
-
使用您编写的代码,您的页面应该默认未选中所有复选框。
-
顺便问一下,你为什么要选中复选框?当页面最初加载时,默认情况下不要选中它们。
标签: javascript