[英]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.