开发者

Pointing to a input field

开发者 https://www.devze.com 2023-01-18 07:17 出处:网络
I dont know how some makes it, but sometime when i enter some sites, it automaticly clicked in the input field for me开发者_JAVA技巧. Example i click search, then on the search page it has \"clicked\"

I dont know how some makes it, but sometime when i enter some sites, it automaticly clicked in the input field for me开发者_JAVA技巧. Example i click search, then on the search page it has "clicked" the field for me, so i just type without clicking my self in it. How can i do that?


Use the focus method when the page loads.

So something like this:

<script type="text/javascript">
    window.onload = function () {
        document.getElementById("id-of-some-input-field").focus();
    }
</script>


You can do this by setting the so called "focus" on the input field you require. This can be done by using javascript. Here's an example, I hope it helps you!

<html>
<head>
<title>Focus Example</title>
  <script>
    function setFocus() {
      var loginForm = document.getElementById("login");
      if (loginForm) {
        loginForm["user"].focus();
      }
    }
  </script>
</head>
<body onload="setFocus();">
  <form id="login" method="post" action="">
    <table>
      <tr>
        <td><div align="left">User Name:</div></td>
        <td><div align="left"><input name="user" type="text"
            size="30" maxlength="30" tabindex="1" /></div></td>
      </tr>
      <tr>
        <td><div align="left">Password:</div></td>
        <td><div align="left"><input name="password" type="password"
            size="30" maxlength="50" tabindex="2" /></div></td>
      </tr>
  </form>
</body>
</html>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号