开发者

how to use accesskey in html

开发者 https://www.devze.com 2023-01-08 21:55 出处:网络
I want my form to automatically switch from the username field to the password field as the user types in their information. I would also like t开发者_如何学Che form to automatically submit when the u

I want my form to automatically switch from the username field to the password field as the user types in their information. I would also like t开发者_如何学Che form to automatically submit when the user presses the Enter key.

How would I do this with HTML?


You need javascript for that:

var el = document.getElementById('field_id');

el.onkeypress = function(event){
  var key = event.keycode || event.which;

  if (key === 13) {
     document.FormName.submit();
  }
};

jQuery: (based on comment)

$(function(){
    $('#form_id:input').keypress(function(event){
      var key = event.keycode || event.which;

      if (key === 13) {
         $(this).parents('form').submit();
      }

    });
});


Example-

<FORM action="..." method="post">
<P>
<LABEL for="fuser" accesskey="U">
User Name
</LABEL>
<INPUT type="text" name="user" id="fuser">
</P>
</FORM>

See details HERE


(http://www.htmlcodetutorial.com/forms/index_famsupp_157.html)

this probably would help ;)

0

精彩评论

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