• 对多个button触发enter操作,执行不同的操作


    1.首先为需要触发enter事件的控件中添加onkeydown事件:

      支持onkeydown事件的标签为:

    <a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>, 
    <button>, <caption>, <cite>, <code>, <dd>, <del>, <dfn>, <div>, <dt>, <em>, 
    <fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <input>, <kbd>, <label>, <legend>, 
    <li>, <map>, <object>, <ol>, <p>, <pre>, <q>, <samp>, <select>, <small>, 
    <span>, <strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, 
    <th>, <thead>, <tr>, <tt>, <ul>, <var>
    则,例如可以对table标签添加onkeydown事件。(此时在table中的标签用键盘输入时都会触发该事件)
    <table onkeydown="keydown(event)"></table>
    View Code

      则,编写keydown方法:

    function keydown(e)
    {
    var keynum;
    
    if(window.event) // IE
      {
      keynum = e.keyCode
      }
    else if(e.which) // Netscape/Firefox/Opera
      {
      keynum = e.which
      }
     if(keynum =='13')
     {
       $(e.target).closest('tr').find('.queryUser').trigger('click');//这样可以获得对应tr下的按钮button触发事件click。
      }
    }
    View Code

    其中:$(e.target)表示,获得当前在哪个标签下按下了“enter”键。closeset("标签或者selector")表示向上找父元素最新匹配的。find("标签或者selector")表示找出该标签下的子元素。

    
    
  • 相关阅读:
    使用session页面控制登录入口及购物车效果的实现
    php中会话保持 session 与cooker
    php多关键字查询
    php后台编辑关联数据
    php后台增删改跳转
    php登录注册页面及加载
    [bzoj4098] [Usaco2015 Open]Palindromic Paths
    [bzoj1969] [Ahoi2005]LANE 航线规划
    4395: [Usaco2015 dec]Switching on the Lights
    [bzoj2789] [Poi2012]Letters
  • 原文地址:https://www.cnblogs.com/minfan/p/6099061.html
Copyright © 2020-2023  润新知