2015-06-11 16 views
0

我正在一個應用程序中,我必須從數據庫中獲取動態值,並且必須動態地將它們附加到我的html div。要更清楚我有4個標籤其中也有4個div,現在我必須做的,我必須追加4個值,我將從數據庫動態地獲取到4個div。我在這裏發佈我的代碼到目前爲止,我已經做了什麼,有人請幫助如何使用j追加值到html div ids查詢

這是我的HTML部分,在那裏我有4個格

<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的到底哪裏我得到4 values.Now我想他們追加動感中LLY每次.Posting我的代碼在這裏

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); 

地址1,地址,城市,primaryPhone是。什麼我都試過我做

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

但這不是工作me.Please有人把參數幫我解決這個問題。

+0

做了你的變量是看到那裏,把控制檯,看看你是否得到這個價值或不 – Selva

+0

$('#address1ForLabe2')。data(address2);不工作 – lucifer

+0

@ArunprasanthKV address1ForLabe2是div id – lucifer

回答

0

你可以嘗試在一個額外的<div>追加你的價值:

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

或代替原來的<label>

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

作業的左側必須是一個變量錯誤,顯示 – lucifer

+0

有人幫助請求 – lucifer

0

溶液

 $('#address1ForLabel').text(address1); 
     $('#address2ForLabel').text(address2); 
     $('#cityForLabel').text(city); 
     $('#primaryPhoneForLabel').text(primaryPhone); 
+0

這將取代舊數據。你要追加 –