0

When have a list of input buttons on the UI which sill submit a form.

New requirement is to disable the button after click it. I have tried

j("input.allowed-task").each(function() {
document.getElementById(j(this).attr('id')).disabled = true;
});

and

j("input.allowed-task").attr('disabled', 'disabled');

It all works fine on firefox, IE8, IE9

But when it comes to IE7, neither of above method works. All processes are ignored after the button is disabled, so the form is not even get submit, really don't have an idea how to fix it.

BTW we are on jquery 1.4 so .prop is not supported

4

4 回答 4

2

我建议使用提交事件而不是单击,这样你就可以确保你抓住它,否则人们仍然可以通过按输入来提交。

$("#myform").submit(function(e){
    // prevent default so that we completely control when the form submits
    e.preventDefault();
    var $form = $(this);
    if ( !$form.data("submitted") ) {
        // form hasn't been submitted yet, set flag, disable button, then submit the form.
        $form.data("submitted",true);
        $("#submitbtn").attr("disabled","disabled"); 
        // obviously disable whatever you need to, 
        // you don't HAVE to disable it though because
        // the flag and e.preventDefault will prevent
        // them from submitting anyway.
        this.submit(); // submits the form, bypassing this submit handler
    }    
});
于 2013-10-01T20:20:25.720 回答
0

也许这就是您正在寻找的:

j('input.allowed-task').click(function () {
    // Disable the element
    j(this).attr('disabled', 'disabled');

    // Submit the form
    j(this).closest('form').submit();
});
于 2013-10-01T19:52:47.720 回答
0

似乎您应该能够直接在代码中提交表单。

j("input.allowed-task").click(function() {

    // disable all buttons
    j("input.allowed-task").attr('disabled', 'disabled');

    // submit the form
    YOUR_FORM.submit();

    return false;
});
于 2013-10-01T19:47:07.230 回答
0

replaceWith()可用吗?

j("input.allowed-task").replaceWith('<input type="submit" disabled="disabled">');
于 2013-10-01T20:05:34.373 回答