<按钮>防止&#39;空间&#39;单击

时间:2017-08-17 14:57:22

标签: jquery html events button

我有<button>通过按空格键来激活,这是我不想要的,所以我使用e.preventDefault();也禁用了 &#39;单击&#39;事件,但按钮&#39;保持视觉和压力#39;有什么问题吗? 使用e.stopPropagation();完全没有效果。

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


$("#foo").click(function(){
 alert("Button stay 'pressed' until close the alert!");
});
&#13;
<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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

如果您想设置一个已被点击的按钮&#39;看起来它没有,你可以在你的CSS中使用:active。 e.g。

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

相关问题