jquery如何对多个对象绑定同一事件

用jquey循环三个元素对象,其中首先利用jquery的选择器选取id为edit的包装集,利用jquery内置的each方法枚举每个对象
同时在对象的事件上绑定函数至,本例使用了点击事件,当事件触发时将屏幕弹出一个简单的窗口。 例子:
$("a[id='edit']").each(function (index) {
       $(this).click(function(){alert('sfsafasdf');});
    });

    $("a[id='add']").each(function (index) {
       $(this).click(function(){alert('sfsafasdf');});
    });

posted @ 2012-05-27 11:38  范永强  阅读(289)  评论(0编辑  收藏  举报