更新动态生成的元素的属性

问题描述

嗨,大家好,我在更新某些动态生成元素的属性时遇到了问题。事实是,它们不是使用javascript DOM完全动态生成的,例如'document.createElement(“ image”)',我有两个小的.PHP文件,它们已经包含必须显示的所有标签和元素(带有样式的.classes和#ID等),以及在发生适当单击时,则两个文件都将被“加载”到ID为“ DIV_load_aceptor”的指定DIV中。还要增加难度(?)的是Buttons_1和_2以及#DIV_load_aceptor都是动态生成的。 (同样,将文件加载到“ super-div”中。

动态生成的(而不是.load()-ed)HTML段是考虑的:

<button id="Button_1">Image</button>
<button id="Button_2">Data</button>

<DIV id="DIV_load_aceptor">
    // PHP Files are loaded here
</DIV>

将要加载的两个PHP文件是:

<DIV id="Image_Container">                 //1. FILE_IMAGE.PHP
    <img id="First_Image" src="">
    <label id="filename"></label>
    <label id="filetype"></label>
    <label id="filesize"></label>
</DIV>
<DIV id="User_Container">                 //2. FILE_USER.PHP      
    <img id="Another_Image" src="">
    <label id="Username"></label>
    <label id="USertype"></label>
    <label id="Useremail"></label>  
    //more elements,Could be anything,this is just a simple example.  
</DIV>

Jquery / Javascript组合是

$("#Button_1").click(function(){
    $("#DIV_load_aceptor").load("FILE_IMAGE.PHP");
    
    aj = new XMLHttpRequest();  ///ajax to get some more details for attributes     
    {//aj readystate checks 
                
        var DATA_ = JSON.parse(aj.responseText);
        $("#First_Image").attr("src",DATA_.IMG_SRC);
        $("#filesize").html(DATA_.IMG_SIZ); 

        //etc etc
    }
    aj.open("post","DATABASE_QRY_IMG_details_Json_return",true);
    aj.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    aj.send(some data);
});

$("#Button_2").click(function(){
    $("#DIV_load_aceptor").load("FILE_USER.PHP");
    
    aj = new XMLHttpRequest();  
    {   var DATA_  = JSON.parse(aj.responseText);
        $("#Another_Image").attr("src",DATA_.IMG_SRC);
        $("#Username").html(DATA_.UNAME);
        
        //etc etc
    }
    aj.open("post","DATABASE_QRY_USER_Json_return",'application/x-www-form-urlencoded');
    aj.send(some data);
});

不要奇怪,它不起作用。小PHP文件中的元素和标记属性未更新。事实是,小的PHP文件中的标签很多(上面的代码只是一个精简版本以说明问题。)这就是为什么如果我继续使用javascript逐个创建它们,那会花费很多时间(并变得乏味)。有没有办法更新这些元素的属性?从文件加载元素后,如何将元素附加到DOM?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)