通过ajax注入html,RE-RUN document.ready()jqueries,IS可能吗?

here is my case:

    <html>
    <body>
    <head>
    ...
    <script>
 $(function(){
        $('.do-tip').qtip({
            content: 'This is a tip of active hovered element',
            show: 'mouseover',
            hide: 'mouseout',
  })
 });
    </script>
    </head>
    <body>
    <a href="http://www.google.com" class="do-tip">google</a>

    <input type="button" value="load div by ajax" />
    <div> <!-- this div loaded by ajax -->
    <div>
    <a href="http://www.yahoo.com" class="do-tip">yahoo</a> <!-- HOW TO HERE, run the existing script only for this part, JQUERY UNCLE must have a solution-->
    </body>
    </html>

any ideas?
    
已邀请:
虽然我不清楚你要做什么,但我会尝试使用我的MagicGuess工具并为你提供答案。 所以,你需要 a)对文档加载执行一些功能;此功能与页面上的所有
.do-tip
元素相关 b)通过AJAX加载东西后执行相同的功能,但现在需要使用另一组元素进行操作。 真的吗?如果是这样,我会这样做:
function doEverythingINeed(selector) {
    $(selector).qtip({
        content: 'This is a tip of active hovered element',
        show: 'mouseover',
        hide: 'mouseout',
    })

}

$(function() {
    doEverythingINeed('.do-tip');
});
在通过AJAX加载HTML后,使用另一个选择器调用
doEverythingINeed
。如果你使用
$.ajax()
功能,那么你应该这样做
$.ajax({
    //parameters
    success: function() {
        //some other actions if needed
        doEverythingINeed('your selector');
        //more actions if needed
    }
});
希望有所帮助!     
为了防止其他人,我有一个非常相似的用例并用jQuery的.live()事件绑定器解决了它 - 比我试图通过重新处理所有$('document')而设计的解决方案简单得多。 ()事件。 用例:包含大量链接(HTML标签)的页面。在$('document')。ready()我将相关链接的.click()事件绑定到一个调用某个.ajax()的函数,该函数检索更多相同类型的链接并将其HTML注入页面。问题是,新链接没有绑定。单击新链接不会像它应该触发.ajax()代码。 在注入HTML之后,我花了很多时间尝试重新触发ready事件,然后意识到用.live('click)而不是.click()绑定事件会得到完全相同的结果,零额外的代码。 顺便说一下,其他人已经给出了其他地方原始问题的非常好的解决方案 - 见问题2238030     
您可以将模块执行控制器内置到就绪函数中,并在注入HTML后重新运行这些函数。像这样的东西: https://gist.github.com/miguel-perez/476046a42d229251fec3     

要回复问题请先登录注册