开发者

How to add click event for many buttons JQuery?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜