gpt4 book ai didi

javascript - jQuery Append 删除标签

转载 作者:行者123 更新时间:2023-11-28 01:42:29 26 4
gpt4 key购买 nike

我尝试使用 jQuery Append 方法,但它删除了我要 append 的 html 代码的标签 (tr, td)。为什么要删除这些以及我如何强制此方法仅 append 而不分析我的代码?

这是一个示例文件

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script>
<script type="text/javascript">
$(document).on('click', '#button1', function () {
var htmlAppend = '';
htmlAppend = htmlAppend + '<input type="hidden" name="content0" value="' + 'hiddenvalues' + '"/>' + '<tr>' +
'<td>' + 'content1' + '</td>' +
'<td>' + 'content2' + '</td>' +
'<td>' + 'content3' + '</td>' +
'<td><input style="width: 300px" type="text" name="content4"/></td>' +
'</tr>';
$("#ScenarioCompetenceRatings").append(htmlAppend);
});
</script>
</head>
<body>
<button id="button1">Add Row</button>
<table>
<thead>
<tr>
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
<th style="width: 300px">Column4</th>
</tr>
</thead>
<tbody id="ScenarioCompetenceRatings">

</tbody>
</table>

最佳答案

您正在生成无效标记。您应该将隐藏的 input 元素放在 td 元素中。 tbody 元素只能有 tr 子元素。

关于javascript - jQuery Append 删除标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25057963/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com