我有一个输入搜索字段。现在,在jquery中动态创建表单期间,此搜索字段将从其父div中删除,并被添加到新表单中。此外,没有创建应该创建的类型为hidden的动态输入。请在下面找到我的代码。请帮助解决此问题。预先感谢。
HTML
<body>
<div class="searchArea">
<input id="searchField" name="searchNotice" type="text">
<button id="searchButton" class="iconButton" data-tooltip-text="Search"><i class="fy fy-magnify"></i></button>
</div>
<div class="downloadArea">
<button id="downloadIDPDF" ntag="6">Download ID Card</button>
</div>
</body>
JQuery
$('#downloadIDPDF').click(function()
{
$empID = $(this).attr('ntag');
var url = './lib/emp_id_pdf.lib.php';
$("<form>")
.attr("action", url)
.attr("method", "post")
.append($("input").attr("type", "hidden").attr("name", "emp_id").attr("value", $empID))
.appendTo("body")
.submit()
.get(0)
.reset()
.remove();
});
最终HTML
<body>
<div class="searchArea">
<button id="searchButton" class="iconButton" data-tooltip-text="Search"><i class="fy fy-magnify"></i></button>
</div>
<div class="downloadArea">
<button id="downloadIDPDF" ntag="6">Download ID Card</button>
</div>
<form action="./lib/emp_id_pdf.lib.php" method="post">
<input id="searchField" name="searchNotice" type="hidden" value="2">
</form>
</body>