开发者

Pointing to a input field

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜