zoukankan      html  css  js  c++  java
  • JS——JS和JQuery实现Button绑定键盘Enter事件实现提交

    需求:当用户在输入表单信息后无需点击确认按钮,回车实现表单提交

    场景:登录、提交个人信息等

    技术:通过键盘事件来实现相关需求,除此之外还可以实现各种和键盘有关的需求

    JavaScript实现方法

    document.onkeydown = function(e) {
        if (!e)
            e = window.event;//火狐中是 window.event
        if ((e.keyCode || e.which) == 13) {
            document.getElementById("loginButtonId").click(); //loginButtonId为button登录按钮的ID  
        }
    }

     jQuery实现方法

    $(window).keydown(function(e){
        var curKey = e.which; 
        if(curKey == 13){
            $('#loginFormId').submit(); //loginFormId为form表单的ID
        }
    })
  • 相关阅读:
    未格式化的输入/输出操作
    格式化输入与输出
    随机数
    正则表达式
    bitset
    tuple
    servlet笔记
    springside
    maven
    Lua简易入门教程
  • 原文地址:https://www.cnblogs.com/kitor/p/11213107.html
Copyright © 2011-2022 走看看