Firefox下如何將斷行符號鍵轉為Tab鍵

來源:互聯網
上載者:User
文章目錄
  • 採納的答案
在Form裡有多個輸入欄位,通過Tab可以在這些輸入欄位中導航,需要使用者敲入斷行符號鍵的效果和Tab見一致,即將
斷行符號鍵轉為Tab鍵

IE下可以實現,代碼如下 Html代碼

  1. <html xmlns="http://www.w3.org/1999/xhtml">  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  4. <title>無標題文檔</title>  
  5. <script type="text/javascript">  
  6. function enterToTab(event){   
  7.   var e = event?event:window.event   
  8.   if(e.keyCode == 13){   
  9.      e.keyCode = 9;   
  10.   }   
  11. }   
  12. </script>  
  13. </head>  
  14.   
  15. <body>  
  16. <form>  
  17. <input id="input1" type="text">  
  18. <input id="input2" type="text">  
  19. <input id="input3" type="text">  
  20. <input id="input4" type="text">  
  21. </form>  
  22. </body>  
  23. </html>  
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><script type="text/javascript">function enterToTab(event){var e = event?event:window.eventif(e.keyCode == 13){e.keyCode = 9;}}</script></head><body><form><input id="input1" type="text"><input id="input2" type="text"><input id="input3" type="text"><input id="input4" type="text"></form></body></html>

但是在FireFox下事件的keyCode 是唯讀,不能修改,不知Firefox下如何?這個功能

採納的答案
  1. function enterToTab(obj, event){     
  2.   var e = event?event:window.event     
  3.   if(e.keyCode == 13){     
  4.      obj.nextSibling.focus();   
  5.      return false;   
  6.   }     
  7. }   
function enterToTab(obj, event){var e = event?event:window.eventif(e.keyCode == 13){obj.nextSibling.focus();return false;}} 

函數多傳一個參數,就是當前DOM的this, 原理就是entry當前的input, 就讓滑鼠焦點獲得到下一個input框

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.