开发者

jquery: disable submit button in a form and enable it onChange of any element on the form

I need to disable the disable the submit button on my form and to enable if the onchange event occurs for any other input on the form

so basically I need to:

  • disable the submit button
  • add a method that enbales the submit button to the onchange event for all the ot开发者_StackOverflow中文版her inputs on the form

anybody knows how to do this ? (especially the second one)


Using jQuery 1.4:

// To disable submit button
$('#myform').find (':submit').attr ('disabled', 'disabled');

// Re-enable submit
var form = $('#myform');
$(':input', form.get(0)).live ('change', function (e) {
    form.find (':submit').removeAttr ('disabled');
});


Try this:

$("form").submit(function() {
    $(this).find(":submit").attr("disabled", "disabled");
}).find(":input").change(function() {
    $(this).parent("form").find(":submit").removeAttr("disabled");
});


Something like this:

$("#myform").children().change(function(){
   $("#submit").removeAttr('disabled');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜