gpt4 book ai didi

javascript - 如何使用 j Query 将值附加到 html div id

转载 作者:行者123 更新时间:2023-11-28 07:44:27 26 4
gpt4 key购买 nike

我在一个应用程序中工作,我必须从数据库中获取动态值,并且必须动态地将它们附加到我的 html div。更清楚地说,我有 4 个标签,其中也有 4 个 div,现在我必须做,我必须附加 4 个值,我将从数据库动态获取这些值到那 4 个 div。我在这里发布我的代码,我到目前为止所做的,有人请帮忙

这是我的 html 部分,其中有 4 个 div

<div id="primaryLabel">
<table id="personalInformation">
<tr>
<th>Address 1<span style='color: #FF0000; display: inline;'>*</span></th>
<td><label for="address1" id="address1ForLabel" ><%=address1 %></label></td>
<td><a href="#" onclick="open_new();"><img style="border:0;" src="<%=request.getContextPath()%>/images/edit.png" title="Click to edit"></a> </td>
</tr>
<tr>
<th>Address 2<span style='color: #FF0000; display: inline;'>*</span></th>
<td><label for="address2" id="address2ForLabel"><%=address2 %></label></td>
</tr>
<tr>
<th>City<span style='color: #FF0000; display: inline;'>*</span></th>
<td><label for="city" id="cityForLabel"><%=city %></label></td>
</tr>
<tr>
<th>Primary Phone<span style='color: #FF0000; display: inline;'>*</span></th>
<td><label for="primary phone" id="primaryPhoneForLabel"><%=primaryPhone %></label></td>
</tr>
</table>
</div>

这是我的 javascript/jQuery 端,我在其中获得四个值。现在我想每次都动态附加它们。在这里发布我的代码

 jQuery.getJSON(url+"&address1="+address1+"&address2="+address2+"&country="+country+"&state="+state+"&city="+city+"&zip="+zip+"&skypeId="+skypeId+"&twitter="+twitter+"&primaryPhone="+primaryPhone+"&secondaryPhone="+secondaryPhone+"&type="+type, function(data) {

$( "div.success" ).fadeIn( 300 ).delay( 2500 ).fadeOut( 400 );

for(var z=0; z<data.applicationArray.length;z++){

applicationArray = data.applicationArray[z].split("$$##$$##");

address1 = applicationArray[0];
address2 = applicationArray[1];
city = applicationArray[2];
primaryPhone = applicationArray[3];

}
alert(address1+":"+address2+":"+city+":"+primaryPhone);

address1 ,address2,city,primaryPhone 是那些参数。我已经尝试过我已经完成了

        $('#address1ForLabel').html(address1);
$('#address1ForLabe2').append(address2);
$('#cityForLabel').html(city);
$('#primaryPhoneForLabel').html(primaryPhone);

但这对我不起作用。请有人帮我解决这个问题。

最佳答案

您可以尝试将您的值附加到额外的 <div> 中:

$('#address1ForLabel').append('<div>'address1'</div>');

或替换原来的<label> :

$('#address1ForLabel').replaceWith("<label for="address1" id="address1ForLabel" >" address1 "</label>")

关于javascript - 如何使用 j Query 将值附加到 html div id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30778584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com