gpt4 book ai didi

JQuery .html() 去除 tr/td 标签?

转载 作者:行者123 更新时间:2023-12-03 22:33:36 26 4
gpt4 key购买 nike

http://jsfiddle.net/WXG7V/

正如您在下面看到的,我有一个简单的 div,其中包含我想要附加到表格末尾的行。如果我使用“.html()”将 div 的内容提醒回屏幕,jQuery 会删除所有 td/tr 标签。

<html>
<head>
<title>jQuery Strips Table Tags</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready( function() {

alert($("#newRow").html());
$(".tasks > tbody:last").append($("#newRow").html());
});
</script>
</head>
<body>
<table class="tasks" style="margin-left: 0px;">
<tr>
<th>Feeder ID</th>
<th>From</th>
<th>To</th>
<th># Reels</th>
<th>Reel Length</th>
<th>Type</th>
<th>Colour</th>
</tr>
</table>
</div>

<div id="newRow" style="display: none;">
<tr>
<td><input type="text" name="feeder_id" id="feeder_id" /></td>
<td><input type="text" name="from" id="from" /></td>
<td><input type="text" name="to" id="to" /></td>
<td><select name="number" id="number">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=6>6</option>
<option value=8>8</option>
<option value=9>9</option>
<option value=12>12</option>
<option value=14>14</option>
<option value=16>16</option>
</select></td>
<td><input type="text" name="length" id="length" /></td>
<td><select name="type" id="type"><option value="CU">Copper</option><option value="AL">Aluminum</option></select></td>
<td><input type="radio" name="colour" id="black" value="black" />Black
<input type="radio" name="colour" id="red" value="red" />Red
<input type="radio" name="colour" id="blue" value="blue" />Blue
<input type="radio" name="colour" id="white" value="white" />White
<input type="radio" name="colour" id="green" value="green" />Green
</td>
</tr>
</div>

最佳答案

<tr> , <td>仅是 <table> 内的有效元素。使用display: table-rowdisplay: table-cell<div> 结合使用替换 <tr><td> .

示例:

<div class="table">
<div class="row">
<div class="cell">
Foo
</div>
</div>
</div>

CSS:

.table{
display: table;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
}

关于JQuery .html() 去除 tr/td 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7539493/

26 4 0