且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果三个特定下拉列表字段中的所有三个均为空,则禁用提交按钮

更新时间:2023-02-01 13:09:05

jsFiddle演示

jsFiddle Demo here

您必须测试的三个选择都可以具有一个类(类似于require_one).

The three selects you must test can each have a class (something like require_one).

更改任何选择框后,请检查其是否具有该类.如果是这样,请从选择"按钮中删除禁用的属性.

When any select box is changed, check if it has that class. If so, then remove the disabled attribute from the Select button.

示例代码:

$('#mySubmit').attr('disabled','disabled');

$('select').change(function(){
    if ( $(this).hasClass('require_one') ){
        $('#mySubmit').removeAttr('disabled');
    }
});


对于您自己的代码,请尝试将其简化为这样,然后看是否可行:


For your own code, try reducing it to just this and see if it works:

$(document).ready(function() {
    $('#sseomodal-submit').attr('disabled', 'disabled');

    $('[id^=sseomodal]').change(function() {
        var myId = $(this).attr('id');
        if (myId == 'sseomodal-level' || myId == 'sseomodal-username' || myId == 'sseomodal-logged') {
            $('#sseomodal-submit').removeAttr('disabled');
        }
    });

}); // END document.ready