2017-08-17 54 views
-1

我这是按“空格键”,这是我不希望启动一个<button>,所以我用e.preventDefault();这也禁用了 “click”事件,但是“按钮”住宿视觉上'按下'。有没有修复? 使用e.stopPropagation();完全没有效果。<button>防止“空间”点击

$("#but").click(function(event){ 
 
    event.preventDefault(); 
 
}); 
 

 

 
$("#foo").click(function(){ 
 
alert("Button stay 'pressed' until close the alert!"); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="foo"> 
 
    <button id="but">button</button> 
 
</div>

+3

恐怕你的问题很难理解,因此人们将努力帮助你和你的问题很可能被关闭。如果你可以提供一些代码,理想情况下在jsFiddle或类似的复制问题,并澄清问题,它会帮助你得到答案。 – Yoda

+0

增加了一些代码。 –

回答

0

如果你想的风格,已经“点击”看起来像没有,你可以在你的CSS使用:active按钮。 例如

button:active { // reset the 'pressed' styles here. }