2010-05-04 25 views
1

我在我的aspx頁面中使用了一個javascript FocusChange()。我有幾個控件,我需要按下Enter鍵來移動下一個基於Tab索引的控件。它在IE7中工作良好,但不能在IE8中工作...請幫助我。自動對焦(點擊輸入)Javascript功能在IE7中運行良好,但不能在IE8中工作

感謝您的幫助提前。 Java腳本如下。

function FocusChange() { 
    if (window.event.keyCode == 13) { 

     var formLength = document.form1.length; // Get number of elements in the form 
     var src = window.event.srcElement; // Gets the field having focus 
     var currentTabIndex = src.getAttribute('tabindex'); // Gets its tabindex 

     // scroll through all form elements and set focus in field having next tabindex 
     for (var i = 0; i < formLength; i++) { 
      if (document.form1.elements[i].getAttribute('tabindex') == currentTabIndex + 1) { 
      for (var j = i; j <= formLength; j++) { 
       if (document.form1.elements[j].disabled == false) { 
         document.form1.elements[j].focus(); 
         event.returnValue = false; 
         event.cancel = true; 
         return; 
         } 
        } 
       } 
      } 
     } 
    } 
+0

嘿,爲什麼不使用jQuery? – 2012-05-24 07:17:28

回答

-1

我有你同樣的請求,但解決它以不同的方式,只需更換輸入標籤

<script language="JavaScript"> 
    document.onkeydown = myOnkeydown; 
    function myOnkeydown() 
    {   
     var key = window.event.keyCode; 
     if (key == 13) //13 is the keycode of the 'Enter' key 
      {window.event.keyCode = 9; //9 is the code for the 'Tab' key. Essentially replacing the Enter with the Tab. 
     } 
    } 
    </script> 

警告:在IE只。

相關問題