2017-02-25 45 views
-1

我在舊問題中嘗試了一些方法,但它不適用於chrome。JQuery .attr('disabled',true)不能在chrome中工作

可以請任何人建議我solution.i'm使用PHP進行驗證。

如果我點擊提交按鈕兩次通過一個錯誤,所以限制問題我禁用提交按鈕,但它不工作在鉻。

<script> 
jQuery(document).ready(function() { 
    jQuery('#submit_button').click(function() { 
    jQuery('#submit_button').attr('disabled','disabled'); 
    }); 
}); 
</script> 
+1

使用'.prop()''即jQuery的( '#submit_button')丙( '禁用',真正的);'爲什麼不能簡單'this.disabled = TRUE;' – Satpal

+0

你的代碼工作好,在Chrome上進行測試。請確保你已經導入jQuery庫。 –

+0

我錯過了一些有問題的想法。在crome中禁用後,重定向是執行重定向不在鉻 –

回答

1

這可能是因爲頁面上有多個提交按鈕。您可以嘗試使用此代碼。

jQuery(document).ready(function() { 
jQuery('#submit_button').click(function() { 
    // It is best practice to use `true` instead of 
    // any true-y kind of value like non-empty string. 
    jQuery(this).attr('disabled', true); 
    }); 
}); 
1

可以使用$('selector').prop('disabled',true);

1

嘗試,使用元素的prop並使attribute true,則使用

jQuery('selector').prop('disabled',true);

<script> 
    jQuery(document).ready(function() { 
     jQuery('#submit_button').click(function() { 
      jQuery('#submit_button').prop('disabled',true); 
      }); 
    }); 
</script> 

我怎麼會添加禁用:

<script> 
$(document).ready(function(){ 

     $('button').click(function() { 
      $('<input type="button id="submit_button" disabled>').insertBefore(this); 
      $(this).remove(); 
     }); 
}); 
</script> 

我怎麼會改變按鈕恢復正常:

<script> 
$(document).ready(function(){ 

     $('button').click(function() { 
      $('<input type="button id="submit_button" >').insertBefore(this); 
      $(this).remove(); 
     }); 
}); 
</script> 
3

你可以使用道具jQuery的方法,或只設置殘疾人屬性true

$(document).ready(function(){ 
 
\t $('#submit').on('click', function(e){ 
 
\t \t //$(this).prop('disabled', true); 
 
\t \t this.disabled = true; 
 
\t }) 
 
});
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width"> 
 
    <title>JS Bin</title> 
 
</head> 
 
<body> 
 
\t <button id="submit">submit</button> 
 
<script src="https://code.jquery.com/jquery-3.1.0.js"></script> 
 
</body> 
 
</html>

0

有不同的想法,但給出的代碼似乎正常工作。請確保您導入了jQuery庫。

以下代碼是經過測試的代碼。 。

<!DOCTYPE html> 
<html> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
<script> 
jQuery(document).ready(function() { 
    jQuery('#button').click(function() { 
     jQuery('#button').attr('disabled','disabled'); 
    }); 
}); 
</script> 
</head> 
<body> 

<input type="submit" id="button" value="If you click on me, I will be disabled."/> 

</body> 
</html> 
相關問題