Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在jquery中操作动态生成的html元素_Javascript_Jquery_Html - Fatal编程技术网

Javascript 在jquery中操作动态生成的html元素

Javascript 在jquery中操作动态生成的html元素,javascript,jquery,html,Javascript,Jquery,Html,我这里有个小问题。?如何在Jquery中操作动态生成的html 我有一个类似于: generatesomething : function(DestinationID,data){ result = $.DoSomething(data) $('#'+Destinationid).html(data); } 换句话说,脚本通过ajax接收一个数组。当然,我将迭代数组,如下所示: $.each(response, function(key, value){ ThisHtm

我这里有个小问题。?如何在Jquery中操作动态生成的html

我有一个类似于:

generatesomething : function(DestinationID,data){
    result = $.DoSomething(data)
    $('#'+Destinationid).html(data);
}
换句话说,脚本通过ajax接收一个数组。当然,我将迭代数组,如下所示:

$.each(response, function(key, value){
    ThisHtml = '<div id="div'+key'"></div>';
    $('#MyPlaceHolderDiv').html(ThisHTML)
    //In this point, i really need to call my first function
    $.generatesomething('div'+key',data)
    //But not works!!!!
}
这个函数运行得很好。。。如果我能把目的地给它

在脚本的另一部分中,我有一个ajax调用:

Generadisco: function(){
    var datos = {
        "accion":"generadisco"
    };
    $.ajax({   
        type: "POST",
        url: "blahblah.php",
        data: datos,
        dataType: "json",
        success:function(response){

            $.each(response, function(key, value){
                esteHTML = '<div id="divdisco'+key+'"></div>                    
                $('#discosplace').append(estehtml);
                //the div is generated... but when i do...:
                $(this).piegraph('divdisco'+key,'pie', response[3],0,1, "{label} #percent%","{label} ");
                //nothing happens
            });
        }
    });
}
Generadisco:function(){
var datos={
“accion”:“generadisco”
};
$.ajax({
类型:“POST”,
url:“blahblah.php”,
数据:达托斯,
数据类型:“json”,
成功:功能(响应){
$。每个(响应、功能(键、值){
埃斯特姆
$('#discsplace').append(html);
//div已生成…但当我生成时…:
$(this.piegraph('divdisco'+键,'pie',响应[3],0,1,“{label}#percent%”,“{label}”);
//什么也没发生
});
}
});
}

我在您的代码中发现了一些错误:

$('#MyPlaceHolderDiv').html(ThisHTML)
$.generatesomething('div'+ key ,data)
必须是:

$('#MyPlaceHolderDiv').html(ThisHTML);
$.generatesomething('div'+key',data);

还要尝试在函数的第一行添加console.log(DestinationID)以查看传递的参数(DestinationID)

如果在ajax调用后生成动态元素,请尝试使用async:false

$.ajax({ 网址:“abcd.html”, 异步:false
}).then(function())

$中的语法错误。GenerateMething('div'+key',data)
是复制/粘贴错误吗?您能解释一下您到底需要什么吗?看起来你把它弄得太复杂了。这里还有语法错误ThisHtml='';您在控制台中看到了什么?是否存在#myplaceholder div?你能在这里显示你的html吗?console.log()你从请求中收到的数据。确保您的div有一个特定的类(如果有多个div)或一个ID(如果只有一个div),以便您可以使用
$('thediv')对其进行操作我想你是指另一种方式,因为
$.generatesomething('div'+key',data)是一个语法错误。
$('#MyPlaceHolderDiv').html(ThisHTML);
$.generatesomething('div'+key',data);