遍历表行添加类
我有一个如下表:
<table border="1" width="400" cellpadding="3" cellspacing="3">
<tr class="keydown"> <!-- Should this be a class? when down arrow is pressed class="selected" should be applied to this-->
<td>Table Cell</td>
</tr>
<tr class="keydown">
<td>Table Cell</td>
</tr>
<table>
当按下向下箭头键(ascii 40??或31?)时,我希望选择表中的第一行,即应将一个类应用于它突出显示(即更改背景颜色)它。当再次按下向下箭头键时,它应该转到下一行。有这个插件吗?我正在摆弄 jQuery,但我对此完全陌生。
jQuery:
<script type="text/javascript">
$().ready(function() {
$('#keydown').keypress(function() {
$("#keydown").addClass("selected");
});
});
</script>
I have a table such as the follows:
<table border="1" width="400" cellpadding="3" cellspacing="3">
<tr class="keydown"> <!-- Should this be a class? when down arrow is pressed class="selected" should be applied to this-->
<td>Table Cell</td>
</tr>
<tr class="keydown">
<td>Table Cell</td>
</tr>
<table>
As the down arrow key is pressed (ascii 40?? or 31?) I want the first row in the table to be selected, i.e. a class should be applied to it highlight (i.e. change in bg colour) it. When the down arrow key is pressed again it should go to the next row. Is there a plugin for this? I'm messing around with jQuery but I'm a completely new at this.
jQuery:
<script type="text/javascript">
$().ready(function() {
$('#keydown').keypress(function() {
$("#keydown").addClass("selected");
});
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
建议使用 keyup 来做这样的事情,关键信息存储在事件参数中。另外,您准备的文档不正确:
It's recommended to use keyup for things like this, which key information is stored in the event argument. Also, your document ready isn't correct: