为若干表单域添加快捷键

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function access()
  5. {
  6. document.getElementById('myName').accessKey="n"
  7. document.getElementById('myPwd').accessKey="p"
  8. document.getElementById('ie').accessKey="i"
  9. document.getElementById('fx').accessKey="f"
  10. document.getElementById('myButton').accessKey="b"
  11. }
  12. </script>
  13. </head>
  14.  
  15. <body onload="access()">
  16. <form>
  17. 姓名:<input id="myName" type="text" />
  18. <br />
  19. 密码:<input id="myPwd" type="password" />
  20. <br /><br />
  21. 选择您喜欢的浏览器:
  22. <br />
  23. <input type="radio" name="browser" id="ie" value="Internet Explorer">Internet Explorer<br />
  24. <input type="radio" name="browser" id="fx" value="Firefox">Firefox
  25. <br /><br />
  26. <input type="button" value="点击我!" id="myButton" />
  27. </form>
  28.  
  29. <p>(请使用 Alt + <i>accesskey</i> 为不同的表单字段赋予焦点。)
  30. </p>
  31. </body>
  32.  
  33. </html>