2013-06-28 35 views
-2

我做錯了什麼在這裏:的jQuery生成動態表圈

var htmlString ="\ 
       <table width='97%' height='233px' border='1' class='NewTable'>\ 
         <tr>\ 
         <th width='43%'>"+currGroupAry[j]+"</th>\ 
         <th width='8%'>Points</th>\ 
         <th width='49%'>Justification</th>\ 
         </tr>\ 
         <tr>\ 
         <td height='29'>Was willing to frequently share ideas and resources</td>\ 
         <td><input id='TotalTEP1' type='text' value='' readonly /></td>\ 
         <td>\ 
          <table id='gp1' width='100%'>\ 
          "for(var i=0; i<=currGroupAry.length; i++){"\ 
           <tr><td style='width:100px;'>"+currGroupAry[j]+"</td><td><textarea style='width:97%; font-size: 14px; background-color: transparent; border:none; resize:none;' cols='10' rows='2' readonly>"+user.comments[j-1]+"</textarea></td></tr>"}"\ 
          </table>\ 
         </td>\ 
         </tr>\</table>" 

試圖將此表追加到事業部。但沒有工作。中間的For循環有問題。

+0

爲了提供有用的信息,我們需要有關您的問題的全部細節。你期望發生什麼,現在發生了什麼,以及你試圖修復它的是什麼?請包括錯誤消息和/或意外行爲的描述。 –

+0

在htmlString之間有一個for循環,並尋找一個合適的syntex來放置jQuery變量中的for循環。 – fguru

+0

有一個主表,並在一個​​我需要另一個表。 – fguru

回答

2

這是我會怎麼做......鑑於你目前的代碼....但隨後再次....它不是真的我會怎麼做呢.....

var htmlString ="<table width='97%' height='233px' border='1' class='NewTable'><tr><th width='43%'>"+currGroupAry[j]+"</th><th width='8%'>Points</th><th width='49%'>Justification</th></tr><tr><td height='29'>Was willing to frequently share ideas and resources</td><td><input id='TotalTEP1' type='text' value='' readonly /></td><td><table id='gp1' width='100%'>"; 

for(var i=0; i<=currGroupAry.length; i++){ 
htmlString+="<tr><td style='width:100px;'>"+currGroupAry[i]+"</td><td><textarea style='width:97%; font-size: 14px; background-color: transparent; border:none; resize:none;' cols='10' rows='2' readonly>"+user.comments[i-1]+"</textarea></td></tr>"; 
} 

htmlString+="</table></td></tr></table>"; 

而且....不知道如果你想currGroupAry[j]currGroupAry[i],在循環中,你有j,但我更改爲i假設你想循環顯示相關的信息,但改回j,如果這就是你想要的。

+0

KyleK這正是我所期待的。我將它改爲j。但在這一行下得到'用戶沒有定義'的錯誤:htmlString + =「」 – fguru

+0

只是想通了。謝謝你的解決方案KyleK。你是白嘴鴉! – fguru

+0

沒問題! ... :) – KyleK