jQuery追加删除标签

jQuery Append removing tags

本文关键字:标签 删除 追加 jQuery      更新时间:2023-09-26

我尝试使用jQuery追加方法,但它的删除标签(tr, td)我的html代码,我想追加。为什么要删除这些,我怎么能强迫这个方法只是附加,而不是分析我的代码?

下面是一个示例文件

<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子元素。

这是你想要建立的吗?检查我创建的小提琴http://jsfiddle.net/FWkd2/enter code here检查我的小提琴