开发者

How to add click event for many buttons JQuery?

开发者 https://www.devze.com 2023-04-06 04:54 出处:网络
I have buttons that has ids like that: id=\'button0\' id=\'button1\' id=\'button2\' id=\'button3\' id=\'button4\'

I have buttons that has ids like that:

id='button0'
id='button1'
id='button2'
id='button3'    
id='button4'
...

I want to add click event for all of them. How can I do it with most performanc开发者_运维技巧e?


simple

you should use class instead !!!

<span  class="MySpan"> ...

<span  class="MySpan"> ...

<span  class="MySpan"> ...

$(".MySpan").click (....


Starts with (^=)

Something like $("button[id^='button']")

Performance wise - not sure what the impact of ^= would be though.

ref: http://api.jquery.com/attribute-starts-with-selector/


    $("*[id^='button']").click(
        function() {
        }
     );
0

精彩评论

暂无评论...
验证码 换一张
取 消