如何在
HTML表单中启用提交按钮,如果未选中复选框,则禁用?
这段代码有什么问题?
EnableSubmit = function(val)
{
var sbmt = document.getElementById("Accept");
if (val.checked == true)
{
sbmt.disabled = false;
}
else
{
sbmt.disabled = true;
}
}
复选框
<td width="30%">Do you accept Terms of Service agreement?</td>
<td width="10px" style="min-width: 10px"></td>
<td width="70%">
<input type="checkBox" name="TOS" value="Accept" onClick="EnableSubmit"> I agree to Terms of Service agreement.
</td>
解决方法
将您的HTML更改为:
<td width="30%">Do you accept Terms of Service agreement?</td>
<td width="10px" style="min-width: 10px"></td>
<td width="70%">
<input type="checkBox" name="TOS" value="Accept" onClick="EnableSubmit(this)"> I agree to Terms of Service agreement.
</td>
原因不行:你没有传递任何功能.实际上,因为你没有使用带有函数名的括号,所以你根本没有调用这个函数.在onclick HTML事件属性的上下文中传递它意味着您传递对元素的DOM对象的引用,让您访问其checked属性.