我在搜索完全相同的东西时遇到了这个问题。
基本上我有一个文本区域和一个按钮。 button.click在用户按回车时触发。然而:在CSS中的活动选择器没有被触发,所以它不会产生相同的影响。
所以这就是我所做的。它有点多余,但有效。
在CSS
/*this is for actual clicks on the button */
.Button:active {
position:relative;
top:5px;
}
/* this is for pressing enter instead of clicking the button */
.Button.activate{
position:relative;
top:5px;
}
然后在jQuery的
//if enter is pressed, trigger button click
$("#textArea").keydown(function(event){
if(event.keyCode == 13){
$("#button").click();
$("#button").addClass('activate');
}
});
//if enter is released, remove class
$("#textArea").keyup(function(event){
if(event.keyCode == 13){
$("#button").removeClass('activate');
}
});
那如果真的是令人失望的。我知道我还没有找到办法,但我不明白为什么不应该这样做。 =( – 2010-06-09 12:41:41