对多个button触发enter操作,执行不同的操作
生活随笔
收集整理的這篇文章主要介紹了
对多个button触发enter操作,执行不同的操作
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.首先為需要觸發(fā)enter事件的控件中添加onkeydown事件:
支持onkeydown事件的標(biāo)簽為:
| <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> |
則,編寫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');//這樣可以獲得對(duì)應(yīng)tr下的按鈕button觸發(fā)事件click。} } View Code其中:$(e.target)表示,獲得當(dāng)前在哪個(gè)標(biāo)簽下按下了“enter”鍵。closeset("標(biāo)簽或者selector")表示向上找父元素最新匹配的。find("標(biāo)簽或者selector")表示找出該標(biāo)簽下的子元素。
轉(zhuǎn)載于:https://www.cnblogs.com/minfan/p/6099061.html
總結(jié)
以上是生活随笔為你收集整理的对多个button触发enter操作,执行不同的操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP7扩展开发(二):配置项与全局数值
- 下一篇: 构建javaweb项目