[英]removeClass(“disabled”) in JQuery doesn't work correct
我有按鈕:
<button type="button" id="add_argument_button" class="btn btn-default disabled">
<span class="fa fa-plus"></span>
</button>
<button type="button" id="remove_class" onclick="remove_disabled();">
remove
</button>
和js功能:
function remove_disabled(){
$("#add_argument_button").removeClass("disabled);
}
它可以工作,當我單擊第二個按鈕時,第一個按鈕實際上並未禁用,我可以單擊它。 但是按鈕和光標的視圖保持為禁用狀態。 我認為,我需要重新加載第一個按鈕。 為什么我們可以解決這個問題?
您在removeClass語句的末尾缺少雙引號。
$("#add_argument_button").removeClass("disabled");
也許您需要禁用第一個按鈕?
function remove_disabled(){ $("#add_argument_button").removeClass('disabled'); $("#add_argument_button").prop("disabled", true); }
<!DOCTYPE html> <html> <head> <style> </style> <script src="/scripts/snippet-javascript-console.min.js?v=1"></script> </head> <body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button type="button" id="add_argument_button" class="btn btn-default disabled"> <span class="fa fa-plus"></span> </button> <button type="button" id="remove_class" onclick="remove_disabled();"> remove </button> <script type="text/javascript"> </script> </body> </html>
試試這個代碼,它的工作原理
<body>
<button type="button" id="add_argument_button" class="btn btn-default disabled">
<span class="fa fa-plus"></span>
</button>
<button type="button" id="remove_class">
remove
</button>
<div id="logbefore"></div>
<div id="logafter"></div>
</body>
// Add your javascript here
$(function() {
$("#logbefore").text($("#add_argument_button").attr('class'));
$("#add_argument_button").removeClass("disabled");
$("#logafter").text($("#add_argument_button").attr('class'));
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.