繁体   English   中英

如何正确禁用IE10中的按钮?

[英]How to properly disable a button in IE10?

伙计们,我已经在Chrome,Firefox,IE 7 8和9中测试了此代码。只有在IE10中它才起作用。

 $("#upload_file").live('click', function() {
     $('#upload_file').prop('disabled', 'disabled');

     //then do some more codes like ajax
 }

当我单击上载按钮时,它应禁用该按钮,以避免双击。 此功能在IE10以外的其他浏览器上均可正常使用。 在IE10中,它看起来没有被禁用,但是它不会执行下面的其他代码。 所以我假设它确实禁用了功能,而不是按钮

禁用应设置为布尔值:

$('#upload_file').prop('disabled', true);

根据jQuery文档

应该使用.prop()方法而不是.attr()方法来设置禁用和检查状态。

$( "input" ).prop( "disabled", false );

在我看来,您的问题来自使用旧版本的jQuery。 因为我最近在您的jQuery上创建了IE 10,所以我猜它是1.6,它并未针对新版本的浏览器进行优化。 我强烈建议您更新到新版本,除非您要重构现有代码。

通过事件委托与.on()一起尝试:

 $(document).on('click', '#upload_file', function() {
     $(this).prop('disabled', true);
     //then do some more codes like ajax
 });

您可以使用最接近目标元素(“ _#upload_file_”)的静态父元素,目标元素可以是保存按钮的<div>, <table>

要重新启用按钮:

 $(document).on('click', '#upload_file', function() {
     $(this).prop('disabled', true);
     $.ajax({
         url: your url,
         type: your type,
         .......
         success:function(){

         },
         complete:function(){
            $('#upload_file:disabled').prop('disabled', false); //<----here
         },
         error: function(){}
     });
 });

暂无
暂无

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

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