[英]How to set focus on next input when the button "Enter" is pressed? (javascript)
[英]set focus to next input type when side arrow is pressed
如何在td中跳過隱藏的輸入類型並將焦點設置為下一個可見的輸入類型
這是供您參考的表
HTML:
<table border="1" cellspacing="0" id="vitProb">
<tbody>
<tr>
<td>
<input type="text" name="" value="" id="" class="unitfocus0 ">
</td>
<td>
<label id="" class="centerlabeltext">0</label>
<input type="hidden" name="" id="" class="" value="0">
</td>
<td>
<input type="text" name="" value="" id="" class="unitfocus1 ">
</td>
<td>
<input type="text" name="" value="" id="" class="unitfocus2 ">
</td>
<td>
<input type="text" name="" value="" id="" class="unitfocus4 ">
</td>
<td>
<input type="text" name="" value="" id="" class="unitfocus5 ">
</td>
<td>
<input type="text" name="" value="" id="" class="unitfocus6 ">
</td>
</tr>
</tbody>
</table>
這是js代碼:
$(document).delegate('table#vitProb tbody tr td input ' ,"keydown",function(e) {
// get the code of the key that was pressed
var code = e.keyCode ? e.keyCode : e.which;
// varify that side key was pressed
if (code === 39) {
// get the next tr's input field, and set focus to it
var c=this.className;
var a=c.split("");
var m=a[9];
if(isNaN(m))
{ m=0;}
else
{m=parseInt(m)+1;}
var n="unitfocus"+m;
$(this).closest('td').next().find('input[text].'+n+'').focus();
return false;
}
else if (code === 37) {
// get the next tr's input field, and set focus to it
var c=this.className;
var a=c.split("");
var m=a[9];
m=parseInt(m)-1;
if(m==0){m=0;}else{m;}
;
var n="unitfocus"+m;
$(this).closest('td').prev().find('input.'+n+'').focus();
// prevent any default actions
return false;
}
});
如圖所示,下一個箭頭在第一年至第五年的第一年tr中起作用,但是在第一年tr中,箭頭鍵從共享到第一年不起作用
I Unit列在td內有隱藏的輸入類型和標簽
我認為由於隱藏字段箭頭鍵從共享到第一年都無效
如何跳過隱藏的字段並轉到下一個可見的輸入類型。
您已經確定了下一個和上一個元素的類名。 無需調用next()或prev()方法。 這是一個JSFiddle,其中首先選擇父級tr,然后選擇具有正確類的基礎td:
這是我更改的行:
$(this).parents('tr').find('input.'+n+'').focus();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.