当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery实现的回车触发按钮事件功能示例

jQuery实现的回车触发按钮事件功能示例

2018年04月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了jquery实现的回车触发按钮事件功能。分享给大家供大家参考,具体如下:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
  <title>www.jb51.net jquery回车触发按钮事件</title>
  <script src="jquery-1.4.2.min.js" type="text/javascript"></script>
  <script language="javascript" type="text/javascript">
    $(function () {
      $('#submit').click(function () {
        var account = $('#accountinput').val();
        var password = $('#passwordinput').val();
        if (account == '') {
          alert('please input account.');
          $('#accountinput').focus();
          return false;
        }
        if (password == '') {
          alert('please input password.');
          $('#passwordinput').focus();
          return false;
        }
        if (account == 'chad' && password == '123456') {
          alert('login success.');
        }
        else {
          alert('login failed.');
        }
      });
      $(document).keydown(function (event) {
        if (event.keycode == 13) {
          $('#submit').triggerhandler('click');
        }
      });
    });
  </script>
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <table>
      <tr>
        <td> account</td>
        <td><input id="accountinput" type="text" style="width: 150px;" /></td>
      </tr>
      <tr>
        <td>password</td>
        <td><input id="passwordinput" type="text" style="width: 150px;" /></td>
      </tr>
      <tr>
        <td><input id="submit" type="button" value="submit"/></td>
      </tr>
    </table>
  </div>
  </form>
</body>
</html>

运行效果:

ps:关于javascript事件说明可参考本站javascript事件与功能说明大全:

更多关于jquery相关内容感兴趣的读者可查看本站专题:《jquery常见事件用法与技巧总结》、《jquery常用插件及用法总结》、《jquery操作json数据技巧汇总》、《jquery扩展技巧总结》、《jquery常见经典特效汇总》及《jquery选择器用法总结

希望本文所述对大家jquery程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网