且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery不止一次调用函数

更新时间:2023-11-15 09:33:16

我认为它是使用liveclick处理程序. livedocumentbody上附加事件处理程序,并侦听我们通过的选择器.每当您调用getTitles时,它将附加一个新的处理程序.

I think it is the click handler using live. live attachs event handler on the document or body and listens to the selector which we pass. Whenever you call getTitles it will attach a new handler.

看看您的代码,无需使用live即可,只需使用click处理程序即可.

Looking at your code there is no need of using live just use click handler it will work fine.

getTitles

    $('a', list).click(function(e) {
        getItem($(this).attr('data-trnote'));
    });

getItem方法相同

    $('a', list).click(function(e) {
         getItem1($(this).attr('data-flat'), $(this).attr('data-description'));
    });