[英]Handle onkeypress events for focused rowss
我想在具有焦點的表行上的按鍵上調用Java腳本函數。 下面是代碼,但是當我按Enter鍵時,腳本功能沒有被調用。
http://jsfiddle.net/sirishkumar/58FZG/19/
<input id="test" type="text">
<table>
<tr onkeypress="return openLog(e,'row 1')">
<td>Row 1</td>
</tr>
<tr onkeypress="return openLog(e,'row 2')">
<td>Test</td>
</tr>
</table>
var j = jQuery;
var currentRow = 0;
var pagesize = 2;
function ChangeCurrentRow() {
var tableRow = document.getElementsByTagName("tr")[(currentRow % pagesize)];
tableRow.focus();
j(tableRow).siblings().removeClass("highlight-row");
j(tableRow).addClass("highlight-row");
}
j(document).ready(function () {
j('#test').val("Ready");
ChangeCurrentRow();
});
j(document).keydown(function (e) {
if (e.keyCode == 38) {
currentRow--;
ChangeCurrentRow();
return false;
}
if (e.keyCode == 40) {
currentRow++;
ChangeCurrentRow();
return false;
}
});
function openLog(e, id) {
if (e.keyCode == 13) {
$('#input').text(id)
}
return true;
}
行沒有“聚焦”。 您的focus()
無所作為。 只需嘗試寫:
j(tableRow).focus(function(){alert('test');});
tableRow.focus();
而且您什么也看不到=)嘗試處理$(document).keypress()
事件, $(document).keypress()
選定的行進行操作。 onkeypress
for tr-不執行任何操作( contenteditable="true"
tr除外)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.