最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery on click and on enter keyup, different classes - Stack Overflow

programmeradmin0浏览0评论

Desperate late night coding before a submission.

I have two HTML objects with two separate class names that I'm looking to bind the same event with different actionlisteners.

<form class="form-wrapper cf" action ="">
  <input id="searchInput" type="text" placeholder="Search for Sets or Cards" required>
  <button class="searchButton" type="button">Search</button>
</form>

I've managed to handle the button on click, and after reading the documentation for "on" I see that you can bind multiple listeners to the same class. However I can't figure out if it's possible to do the keyup as well.

$(".searchButton").on("click" ,function(){

Desperate late night coding before a submission.

I have two HTML objects with two separate class names that I'm looking to bind the same event with different actionlisteners.

<form class="form-wrapper cf" action ="">
  <input id="searchInput" type="text" placeholder="Search for Sets or Cards" required>
  <button class="searchButton" type="button">Search</button>
</form>

I've managed to handle the button on click, and after reading the documentation for "on" I see that you can bind multiple listeners to the same class. However I can't figure out if it's possible to do the keyup as well.

$(".searchButton").on("click" ,function(){
Share Improve this question edited May 7, 2013 at 8:50 snowp 4911 gold badge6 silver badges22 bronze badges asked May 7, 2013 at 8:46 user1870954user1870954 2073 silver badges14 bronze badges 3
  • 5 .on('click keyup', funciton(){ – elclanrs Commented May 7, 2013 at 8:47
  • Possible duplicate stackoverflow./questions/8608145/… – Mark Walters Commented May 7, 2013 at 8:48
  • @MarkWalters: Question is reversed. I'm looking for two listeners, same event, different objects. He has multiple events, one object, same listener. Not quite it. – user1870954 Commented May 7, 2013 at 9:21
Add a ment  | 

4 Answers 4

Reset to default 7

Try this:

$('.searchButton, #searchInput').on('click keyup' ,function(){

Are you looking for something like this: jsfiddle link http://jsfiddle/XAGD9/2/

$(document).on("click keyup",".searchButton" ,function(){

You can do this:

$(".form-wrapper").on("click keyup", ".searchButton",function(){
    // Your code here
});

try this :

     $(".searchButton").bind("click keyup" ,function(){});
发布评论

评论列表(0)

  1. 暂无评论