2011-11-30 43 views
0

我創建一個函數添加與表中的輸入和選擇框的行數...... 我頁面的結構是行....我想補充以下使用jQuery

<!--FROM HERE--> 
<tr> 
    <th>Track 1:</th> 
    <td><input name="track[]" type="text" class="track" maxlength="150" onkeyup="lookup(this.value);" onblur="fill();"/> 
     <div class="suggestionsBox" id="suggestions" style="display: none;"><img src="images/upArrow.png" style="position: relative; top: -12px; left: 50px;" alt="upArrow" /> 
     <div class="suggestionList" id="autoSuggestionsList">&nbsp;</div> 
     </div></td> 
    <td><img width="27" height="27" src="images/error.png" alt="Error" class="error" id="errorcategory"></td> 
</tr> 
<tr> 
    <th>Category:</th> 
    <td ><select name="category" id="category" style="width:318px;"> 
     <?php getsongcategory($category); ?> 
    </select></td> 
    <td><img width="27" height="27" src="images/error.png" alt="Error" class="error" id="errorcategory"></td> 
</tr> 
<tr> 
    <th valign="top" style="padding-top:12px;">Poet:</th> 
    <td ><select name="poetid" id="poetid" style="width:318px;"> 
     <?php fetch_poet_name($poetid); ?> 
    </select><br/><br/> 
    <input name="poetname" type="text" id="poetname" maxlength="80" onkeyup="lookup(this.value);" onblur="fill();" style="display:none;"/> 
     <div class="suggestionsBox" id="suggestions" style="display: none;"><img src="images/upArrow.png" style="position: relative; top: -12px; left: 50px;" alt="upArrow" /> 
     <div class="suggestionList" id="autoSuggestionsList">&nbsp;</div> 
     </div></td> 
    <td><img width="27" height="27" src="images/error.png" alt="Error" class="error" id="errorpoetid" ></td> 

</tr> 
<tr> 
    <td colspan="3" id="track_1">&nbsp;</td> 
</tr> 

<!---TILL HERE-> 

我想在id="track_1"旁邊添加整個html。這是可能的嗎?因爲我有想法添加輸入並以各種方式選擇....

$("<select/>", { 
    class: 'selectdoctor', 
    name: 'selectdoctor' + i, 
    id: 'selectdoctor' + i 
}).appendTo("#prescriptiondiv").after("<br/>"); 


$("<input/>", { 
    type: 'text', 
    class: 'textinput', 
    name: 'textinput' + i, 
    id: 'textinput' + i 
}).appendTo("#prescriptiondiv").after("<br/><input type='file' id='imageinput"+ i +"' class='imageinput' /><br/><br/>"); 
+0

你想插入所有的HTML到你正在嘗試插入的HTML內的位置嗎?這會導致DOM錯誤,因爲dom樹不能是自引用的。 –

+0

你必須用'$()'使用CSS選擇器,所以'$(「select」)''和'$(「input」)''。 – Viruzzo

回答

0

如果我在那裏你可以考慮使用能夠改變你的HTML和JavaScript的追加到願望位置的模板文件。我使用icanhaz模板庫。

+0

我很困惑這個如何實現我的要求... –

+0

確定了一個想法....但讓我知道如何開始...意味着什麼選擇器需要選擇添加旁邊的'track_id' –