如何使用箭头键在ASP.NET Gridview中上下移动

时间:2012-03-22 07:53:11

标签: javascript asp.net

我有一个网格视图控件在该网格视图控件ItemTemplate我已经采取文本框现在我想做的是按下箭头键,第一行的第一个文本框中的光标将转到第二行的第一个文本框

这是我想要做的网格视图

1 个答案:

答案 0 :(得分:1)

使用此网址,包含代码。 Navigating through text input fields using arrow keys and return

    <script type="text/javascript">
        $(document).ready(function(){ 
           // get only input tags with class data-entry
           textboxes = $("input.data-entry");
           // now we check to see which browser is being used 
           if ($.browser.mozilla) { 
               $(textboxes).keypress (checkForAction);
              } 
          else { 
              $(textboxes).keydown (checkForAction); 
          } 
      });  

     function checkForAction (event) {
          if (event.keyCode == 13 || 40) {
             currentBoxNumber = textboxes.index(this); 
               if (textboxes[currentBoxNumber + 1] != null) {
                   nextBox = textboxes[currentBoxNumber + 1]
                   nextBox.focus(); 
                   nextBox.select();
                   event.preventDefault();
                   return false;
               }
           } 
       }
    </script>
相关问题