繁体   English   中英

IE 7如何在单击后禁用按钮

[英]IE 7 how to disable a button after clicking it

在UI上有一个输入按钮列表,提交表单。

新要求是单击后disable该按钮。 我努力了

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

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

这一切都适用于Firefox,IE8,IE9

但是当谈到IE7时,上述方法都不起作用。 禁用该按钮后会忽略所有进程,因此表单甚至无法提交,实际上并不知道如何修复它。

顺便说一句,我们在jquery 1.4上,所以不支持.prop

我建议使用提交事件而不是单击以便您可以确保捕获它,否则人们仍然可以通过按输入输入来提交。

$("#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
    }    
});

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

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

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

    // submit the form
    YOUR_FORM.submit();

    return false;
});

也许这就是你要找的东西:

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

    // Submit the form
    j(this).closest('form').submit();
});

replaceWith()可用吗?

j("input.allowed-task").replaceWith('<input type="submit" disabled="disabled">');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM