Javascript jQuery-仅在ajax加载特定div后运行脚本
我只想在加载特定div元素时运行脚本。由于网站使用的是ajax,因此在页面加载时,默认情况下不会加载特定的div。只有在特定任务完成后,才会加载div 我尝试了下面的代码,但无法使其工作。怎么做Javascript jQuery-仅在ajax加载特定div后运行脚本,javascript,jquery,Javascript,Jquery,我只想在加载特定div元素时运行脚本。由于网站使用的是ajax,因此在页面加载时,默认情况下不会加载特定的div。只有在特定任务完成后,才会加载div 我尝试了下面的代码,但无法使其工作。怎么做 jQuery( function($){ $(".div_class_here").on("load", function() { // my code goes here }); 您可以在加载div之后使用ajax 例如: jQuery
jQuery( function($){
$(".div_class_here").on("load", function() {
// my code goes here
});
您可以在加载div之后使用
ajax
例如:
jQuery( function($){
$.ajax({
method: "GET",
url: "url",//url get data div
data: { param: "param"}
})
.done(function( result ) {
$(".div_class_here").html(result);
// my code goes here
//run you script here
})
.fail(function() {
alert("error");
});
})
最佳解决方案:让加载div的代码在这里调用您想要的函数