我有一個表,有很多行。例如從一個行(所有行是相同的):使用jquery,用自己的值替換html元素
<tr>
<td>
<input type="text" />
</td>
<td>
<textarea cols="40" rows="3" ></textarea>
</td>
<td>
<select>
//options
</select>
</td>
<td>
<input type="text" />
</td>
<td>
<input type="checkbox" />
</td>
</tr>
行可以被動態地由jquery的按鈕點擊後加入。我試圖做的事: 按鈕後點擊添加新行(我這樣做)並更換前一行HTML元素(輸入類型=文本,文本區域,選擇輸入類型=文本,/[輸入類型=「複選框「必須是安全的])與自己的價值觀。
如果我點擊行(anyrow)之後,我要回滾之前的操作。即用html元素替換文本。和htmlElement.val()=文本。
30分鐘後添加: 我寫了input type = text元素和textarea元素這個。
$("#btnAdd").click(function() {
$input = $('#mainTable tbody>tr:last').closest("tr").find("td > input:text");
$input.replaceWith($input.val());
$textArea = $('#mainTable tbody>tr:last').closest("tr").find("td > textarea");
$textArea.replaceWith($textArea.val());
});
這是個好主意嗎?
我知道,我的英語不是很好。但我正在嘗試與你溝通 – loviji 2010-03-11 08:27:55
@Auurag - 謝謝。 – loviji 2010-03-11 08:38:47
你能改說這部分嗎?你在這裏做什麼 - 「並用自己的值替換以前的Html元素(input type = text,textarea,select,input type = text,/ [input type =」checkbox「必須安全])。 – Anurag 2010-03-11 08:42:40