简体   繁体   English

通过jquery ajax请求在已加载页面上运行jquery代码(加载)

[英]run jquery code on loaded page via jquery ajax request (load)

I am loading an entire middle div via JQuery Ajax call and I simply want to run $(document).ready on the loaded page 我正在通过JQuery Ajax调用加载整个中间div,我只想在加载的页面上运行$(document).ready

header.php loads part of the page header.php加载页面的一部分

var $next = $("<div class='nextab center'>").insertAfter('#content .current');
        $next.load($this.attr('href')+ ' #content .center section' , function(resp) { ...

} }

so for example when header.php loads career.php it does not run all the code that is inside the $(document).ready(function(){ that is on career.php 因此,例如,当header.php加载career.php时,它不会运行在career.php上的$(document).ready(function(){)内部的所有代码

I was thinking of creating a function init on each page loaded but not sure how to call this function from the load callback 我正在考虑在每个加载的页面上创建一个函数初始化,但是不确定如何从加载回调中调用此函数。

Thanks 谢谢

function YourActionOnDocumentReady(){
   // write whatever you want to do     
}

And in document ready call the above function 并准备好在文件中调用上述功能

$(document).ready(function(){
    YourActionOnDocumentReady();
});

And use ajaxStop function to run the same code 并使用ajaxStop函数运行相同的代码

$(document).ajaxStop(function(){
     YourActionOnDocumentReady();
});

Hope it helps... 希望能帮助到你...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM