我有一个javascript例程在一组复选框上执行操作,但最终操作我想将单击复选框设置为选中或取消选中,如果用户是选中该框或取消选中。使用Javascript来检查复选框是否被选中或取消选中
不幸的是,每次我检查它是否被检查或未检查时,它都会返回“on”,表示用户总是检查该框!任何帮助将不胜感激,我也包括了JavaScript。
// Uncheck all the checkboxs with the same Tax Credit
for (i=0; i<arrChecks.length; i++)
{
var attribute = arrChecks[i].getAttribute("xid")
if (attribute == elementName)
{
// if the current state is checked, unchecked and vice-versa
if (arrChecks[i].value == "on") // <-- This is always returning true, even if the box is being unchecked
{
arrChecks[i].checked = 1;
} else {
arrChecks[i].checked = 0;
}
} else {
arrChecks[i].checked = 0;
}
}
在html中检查复选框的正确方法是checked =“checked” – 2009-01-23 16:46:01
您是否考虑过像jquery,prototype,moo或yui这样的库?他们使这个更容易 – 2009-01-23 19:18:45