我在搜索完全相同的東西時遇到了這個問題。
基本上我有一個文本區域和一個按鈕。 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