小编典典

如果选中/取消选中复选框,则启用/禁用提交按钮?

html

如何在我的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>

阅读 498

收藏
2020-05-10

共1个答案

小编典典

将您的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>

原因不起作用:您没有传递任何函数。实际上,由于您没有在函数名称中使用括号,因此根本就没有调用函数。thisonclickHTML事件属性的上下文中传递它意味着您正在传递对该元素的DOM对象的引用,从而使您可以访问其checked属性。

2020-05-10