本文介紹了Jquery 在 Enter 鍵上選擇 NEXT 文本字段的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我使用 jquery 創建了一個頁面,加載時它會自動選擇第一個文本字段.我希望它在按下 ENTER 鍵時移動到下一個字段.
I have made a page using jquery, and on load it selects the first text field automatically. I want it to then move to the next field when the ENTER key is pressed.
$('.barcodeField input').bind('keyup', function(event) {
if(event.keyCode==13){
$("this + input").focus();
}
});
我在網上找不到任何有效的東西.我已經搜索了論壇.
I can't find anything that works on the net. And I've scoured the forums.
推薦答案
我創建了一個小函數,可以滿足你的需求.這是我使用的版本,因此您可能需要更改類名,但您應該明白了.
I've created a little function which can do what you need. This is the version I use so you may need to change the class names but you should get the idea.
<script type="text/javascript">
$(document).ready(function(){
$(".vertical").keypress(function(event) {
if(event.keyCode == 13) {
textboxes = $("input.vertical");
debugger;
currentBoxNumber = textboxes.index(this);
if (textboxes[currentBoxNumber + 1] != null) {
nextBox = textboxes[currentBoxNumber + 1]
nextBox.focus();
nextBox.select();
event.preventDefault();
return false
}
}
});
})
</script>
所以基本上:-
- 獲取所有匹配 .vertical 的輸入字段
- 查找當前文本框
- 尋找下一個
- 將焦點放在那個上
這篇關于Jquery 在 Enter 鍵上選擇 NEXT 文本字段的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!