0
我在每個li中都有單個字符的無序列表。如果用戶按下鍵盤上的任何字母,我想將css類添加到頁面上的相應li。如果用戶按下鍵盤上的A,我想找到具有作爲其內容的Li和添加CSS類到它如何在按鍵中添加css類到li
<div>
<ul class ='list'>
<li>a</li>
<li>b</li>
<li>c</li>
...
<li>z</li>
</ul>
</div>
這是我如何開始這
$(document).keypress(function(e){
var x = e.which;
if((x >= 65 && x <= 90)||(x >=97 && x <= 122)||(x >=48 && x <= 57)) {
checkfirst(x);
}
});
// pick list item with the text content of the value passed
function checkfirst(x){
var y = $('.list').find('li');
// code will go here
//am trying to find the li with text equal to the argument passed
}
請你的HTML代碼添加到這個問題,你已經寫嘗試此實現自己的JS代碼一起。目前你的問題是'爲我寫'我的代碼',很可能會被關閉。 –