2016-11-09 114 views
-2

嗨,大家好我是新的JavaScript語言,問題是在頁面運行按鈕(1)應該被禁用,另一個應該是可點擊的,點擊按鈕(2)啓用按鈕(1) 請幫我...禁用和啓用按鈕

+0

還不如在這裏粘貼代碼,以便我們能夠幫助您更好地 –

+1

歡迎StackOverflow上。請注意,這不是一個免費的代碼寫入服務,但我們渴望幫助其他程序員(和有志之士)編寫他們自己的代碼。請閱讀[如何提出問題](http://stackoverflow.com/help/how-to-ask)上的幫助主題。之後,請用您迄今編寫的代碼更新您的問題,以完成您希望實現的任務。 –

回答

0

您可以使用下面的代碼,將工作,當頁面加載Button1的將被禁用,BUTTON2將被啓用和BUTTON2的Button1點擊將被啓用也就是說

JS:

$("#button1").prop("disabled", true); 

function buttonClick(){ 
$("#button1").prop("disabled", false); 
} 

在HTML:

<input type="button" id="button2" onclick="buttonClick()"> 
0
<html> 

<!-- Include jQuery library --> 
<head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
</head> 

<!-- Your css --> 
<style> 
    #button1, #button2 { 
    width: 70px; 
    height: 30px; 
    background-color: #fff; 
    color: #000; 
    border: 1px solid black; 
    cursor: pointer; 
    } 

    #button1.disabled { 
    cursor: not-allowed; 
    background-color: #e6e6e6; 
    color: #808080; 
    } 
</style> 

<!-- jQuery --> 
<script> 
    $(document).ready(function(){ 

    $('#button2').on('click', function(){ 

     $('#button1').removeClass('disabled'); 
     $('#button1').on('click', function(){ 
      // Your button 1 function 
     }); 

    }); 

    }); 
</script> 

<!-- Content --> 
<body> 
    <div id="button1" class="disabled">Button 1</div> 
    <div id="button2">Button 2</div> 
</body> 
</html> 

希望我回答你的問題。

-1

將下面的css添加到按鈕中: pointer-events:none;

如果u要啓用THW按鈕,添加下面的CSS:

指針的事件:defau