2
A
回答
1
像這樣(用jQuery):
<!DOCTYPE html>
<html lang="en">
<head>
<title>LOL Focus!</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
</head>
<form>
<input class="focusable" type="text" value="lol"/>
<input class="focusable" type="text" value="lol" />
<input class="focusable" type="text" value="lol" />
<input class="focusable" type="text" value="lol" />
<input class="focusable" type="text" value="lol" />
<input class="focusable" type="text" value="lol" />
</form>
<input type="button" id="trigger_button" value="lol" />
<script type="text/javascript">
$(function() {
var focusable = $('.focusable'),
last_element_index = focusable.length - 1,
current_index;
focusable.each(function(i) {
$(this).click(function() {
current_index = i;
})
});
$('#trigger_button').click(function() {
current_index = (should_reset_current_index()) ? 0 : current_index + 1;
focusable[current_index].focus();
});
function should_reset_current_index() {
return (typeof(current_index) === 'undefined') || (current_index == last_element_index)
}
});
</script>
</html>
0
需要在一個前一陣子模仿的標籤功能,現在我已經released it as a library使用jquery。
EmulateTab:一個jQuery插件,用於模擬頁面上元素之間的Tab鍵。
您可以see how it works in the demo。
if (myTextHasBeenFilledWithText) {
// Tab to the next input after #my-text-input
$("#my-text-input").emulateTab();
}
相關問題
- 1. Flex 3:我怎樣才能模擬被按下的輸入/返回鍵
- 2. 我怎樣才能在Android模擬器
- 3. 我怎樣才能模擬Server.HtmlEncode
- 4. Tab鍵給出麻煩。我怎樣才能阻止這
- 5. 模擬Tab鍵在Flex上按下?
- 6. 我怎樣才能關閉鍵盤上的輸入按鍵
- 7. 我怎樣才能
- 8. 元素'tab鍵按訂單
- 9. 我怎樣才能正確地模擬我的controllercontext測試ViewResult.ExecuteResult()?
- 10. 我怎樣才能爲每個外鍵
- 11. Redis:我怎樣才能按鍵排序我的散列?
- 12. 我怎樣才能使周圍按鈕
- 13. 我怎樣才能把differents元素放在我的arrayAdapter中?
- 14. 我怎樣才能下載使用C++
- 15. 我怎樣才能用mockito來模擬最後的方法
- 16. 我怎樣才能設計一個Android項目的模擬器
- 17. Iphone - >我怎樣才能模擬點擊JavaScript的動作?
- 18. 我怎樣才能看到SQLite數據庫(無模擬器)?
- 19. 我怎樣才能從模型
- 20. 我怎樣才能旋轉圖像顯示在HTML按鈕
- 21. 我怎樣才能使用鍵控和向下真假
- 22. 我怎樣才能獲得基於值的鍵在下劃線
- 23. 我怎樣才能不斷更換數組的元素?
- 24. 我怎樣才能讓CSS的JQuery Mobile忽略元素?
- 25. 我怎樣才能得到每個sap.m.select元素的行值
- 26. 我怎樣才能得到watir中隱藏元素的文字
- 27. 我怎樣才能讓DataMapper返回一定數量的元素?
- 28. 我怎樣才能不特定屬性的元素的jQuery
- 29. 我怎樣才能讓這隻有一個元素?
- 30. 我怎樣才能刪除多個文件中的XML元素?
http://stackoverflow.com/questions/1803338/simulate-the-tab-key-function-in-javascript – 2010-06-18 21:51:23
的可能的複製DanC,你有沒有發現該問題的解決方案?我有同樣的任務。 Stephen P,這不是重複的,有些情況下很難找到應該關注的頁面上的下一個活動元素。 – whitered 2010-12-22 09:19:28
Stephen P,不,我沒有找到答案。我重構了我的代碼,以便它可以或多或少地完成這項工作,但我無法模擬按Tab鍵的效果。 – DanC 2010-12-22 13:59:48