Bind an event handler to multiple elements jQuery?

后端 未结 1 1929
太阳男子
太阳男子 2020-12-06 04:38

I\'ve done some experimenting, but can\'t seem to successfully bind one event handler to multiple elements using jQuery. Here\'s what I\'ve tried:

$(\'select         


        
相关标签:
1条回答
  • 2020-12-06 05:02

    To clarify let us extract the selector string into a variable:

    var selector = ['selector1', 'selector2'];
    

    the above is similar to what you have written.

    var selector = 'selector1, selector2';
    

    this is the correct way to use the interface. Note that it is a comma separated list of selector in a single string.

    $('selector1, selector2').bind(...)
    
    0 讨论(0)
提交回复
热议问题