📌  相关文章
📜  如何禁用或启用 jQuery 中的表单提交按钮?

📅  最后修改于: 2021-09-01 02:35:50             🧑  作者: Mango

给定一个 HTML 文档,任务是启用或禁用 jQuery 中的表单提交按钮。

方法:要启用或禁用表单提交按钮,我们使用以下代码片段。

$('#enabled').click(function () {
    if ($('#submit-button').is(':disabled')) {
        $('#submit-button').removeAttr('disabled');
    } else {
        $('#submit-button').attr('disabled', 'disabled');
    }
});

在上面的代码中, enabled是所使用的复选框的 id,而submit-button是所使用的提交按钮的类名。

在上述方法的以下实现中,jQuery-1.11.js 包含在此处找到的源代码 (jQuery v1.11.1)。

示例:下面是上述方法的实现。

HTML


  

    
  
    
        Disable/enable the form submit button
    
  
    
  
    

  

    

GeeksforGeeks

                I accept the terms and         conditionof GeeksforGeeks
                          


输出: