首页  >  文章  >  web前端  >  jQuery实现的回车触发按钮事件功能示例

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

亚连
亚连原创
2018-05-29 09:47:571526浏览

这篇文章主要介绍了jQuery实现的回车触发按钮事件功能,涉及jQuery事件响应及页面元素属性动态操作相关实现技巧,需要的朋友可以参考下

本文实例讲述了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 () {
      $(&#39;#Submit&#39;).click(function () {
        var account = $(&#39;#AccountInput&#39;).val();
        var password = $(&#39;#PasswordInput&#39;).val();
        if (account == &#39;&#39;) {
          alert(&#39;Please input account.&#39;);
          $(&#39;#AccountInput&#39;).focus();
          return false;
        }
        if (password == &#39;&#39;) {
          alert(&#39;Please input password.&#39;);
          $(&#39;#PasswordInput&#39;).focus();
          return false;
        }
        if (account == &#39;chad&#39; && password == &#39;123456&#39;) {
          alert(&#39;Login success.&#39;);
        }
        else {
          alert(&#39;Login failed.&#39;);
        }
      });
      $(document).keydown(function (event) {
        if (event.keyCode == 13) {
          $(&#39;#Submit&#39;).triggerHandler(&#39;click&#39;);
        }
      });
    });
  </script>
</head>
<body>
  <form id="form1" runat="server">
  <p>
    <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>
  </p>
  </form>
</body>
</html>

运行效果:

上面是我整理给大家的,希望今后会对大家有帮助。

相关文章:

vue-cli axios请求方式及跨域处理问题

浅谈React高阶组件

vue数据控制视图源码解析

以上是jQuery实现的回车触发按钮事件功能示例的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn