Home > Web Front-end > JS Tutorial > body text

Example of carriage return trigger button event function implemented by jQuery

亚连
Release: 2018-05-29 09:47:57
Original
1533 people have browsed it

This article mainly introduces the enter trigger button event function implemented by jQuery, involving implementation techniques related to jQuery event response and dynamic operation of page element attributes. Friends in need can refer to the following

This article describes jQuery with examples Implemented enter trigger button event function. Share it with everyone for your reference, the details are as follows:

<!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>
Copy after login

Operation effect:

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future. .

Related articles:

vue-cli axios request method and cross-domain processing issues

A brief discussion of React high-order components

vue data control view source code analysis

The above is the detailed content of Example of carriage return trigger button event function implemented by jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!