javascript - js拼接html的时候怎么让div的id值不同,怎么获取div的id值
怪我咯
怪我咯 2017-04-11 13:21:17
0
7
1294
$.ajax({
                    type: "post",
                    url: "hostPaas.htm",
                    data: {
                    } ,
                    dataType: "json",
                    success: function(data) {
                        var html = "";
                        for (var i=0;i<data.hostPaas.length;i++) {
                             var paasname = data.hostPaas[i].paasName;  
                             var os = data.hostPaas[i].os;
                              var describe=data.hostPaas[i].describe;
                              html +='<li>';
                              html +='<p class="con" id="paasp">';
                              html +='<input type="radio"  class="check" onclick="radio3(this)"value="">' ;
                              html +='<label><em>'+paasname+'</em></label>';
                              html +='</p>';
                              html +='<p class="con" id="paasp2">';
                              html +='<span>'+os+'</span>';
                              html +='</p>';
                              html +='<p class="con">';
                              html +='<span>'+describe+'</span>';
                              html +='</p>';
                              html +='</li>';
                             }
                                $("#paasShow").html(html);
                        },
怪我咯
怪我咯

走同样的路,发现不同的人生

répondre à tous(7)
左手右手慢动作


可以使用 data-id 避免 id 重复的问题

html +='<p class="con" data-id="paasp">';

获取

$('p[data-id=passp]'); // 可以遍历,可以绑定事件,看你的需求
左手右手慢动作

你想问什么没看明白。。id不能直接在代码里改?

刘奇

id后面加个索引....

小葫芦

html +='<p class="con" id="paasp' + i + '">'

左手右手慢动作

id="paasp"+index

左手右手慢动作

通过for循环控制,在循环体里面取变量i的值

巴扎黑

当然可以全局记录id,给重名的加上-1-2……这样的标签以示区分

但是,我觉得你这种情况最好还是直接上命名空间吧,这样更保险。

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!