按代码按TAB

时间:2014-04-09 12:01:36

标签: javascript php jquery tabs

我尝试按代码按TAB;如何在1秒自动按下(标签)后完成代码

if(keycode == '13'){

setTimeout( function(){ 

**// press tab automatic**


} , 1000 );

}
event.stopPropagation();
});

2 个答案:

答案 0 :(得分:1)

可行的解决方案here

以下是来自给定链接的示例:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

    <script type="text/javascript">
      /*************************************************
       * Example showing how to simulate pressing a key.
       *************************************************/

      function pressChar(char)
      {
        try
        {
          // Create the key press event.
          var pressEvent = document.createEvent('KeyboardEvent');
          pressEvent.initKeyEvent("keypress", true, true, window, 
                                    false, false, false, false, 
                                    0, char.charCodeAt(0));

          var input = document.getElementById('input_field'); // Get the element where you want to press.

          input.dispatchEvent(pressEvent); // Press the key.
        }
        catch (e) {
            alert ("Your browser does not support this example!");
        }
      }
    </script>


    <title>Simulate pressing a key</title>
  </head>

  <body>
    <button onclick="pressChar('s')">Simulate pressing the 's' key in the input field.</button>
    <input type="text" id="input_field" />
  </body>

</html>

如果回答您的问题,请将此答案标记为已接受。

答案 1 :(得分:0)

\t是制表符,但它不会发送TAB键移动到下一个对象。

我认为你需要一个像Selenium IDE这样的自动化工具?