[英]JS Display a button when an element is Disabled
第一次來。。。我是JS的初學者。
我只想在其他輸入具有禁用屬性時顯示輸入:
<button type="button" id="Last"> Last </button>
<button type="button" id="Go" style="display:none"> Go </button>
幾次單擊后,並使用jQuery $("#Last").attr("disabled", "disabled"),
我得到了(使用檢查工具):
<button type="button" id="last" disabled="disabled"> Last </button>
我想顯示這個:
<button type="button" id="Go" style="display:block"> Go </button>
我嘗試了這個:
$( document ).ready(function() {
if($("#Last").prop('disabled', true)) {
$('#Go').show();
} else {
$('#Go').hide();
}
});
我不工作! 不知道問題出在哪里!
單擊按鈕時應顯示該按鈕。 請參閱下面的注釋代碼。
// When button is clicked $("#last").on("click", function() { // Set button disabled to true $(this).prop("disabled", true); // Show the #go button $("#go").show(); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button type="button" id="last"> Last </button> <button type="button" id="go" style="display:none"> Go </button>
我已經將id更改為所有小寫字母。 那是一個很好的編碼約定 。
如文檔在此鏈接http://api.jquery.com/prop/上所述,方法prop(name,xxx)將屬性名稱設置為值xxx,在您的代碼中,if語句最后禁用了按鈕。 您應該使用:
if($("#Last").prop('disabled')) $('#Go').show();
請注意,如果將這段代碼放在$( document ).ready
則只有在頁面DOM准備好執行JavaScript代碼后,它才運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.