<form action="${pageContext.request.contextPath }/backend/basic/ticketRule/ticketAuditer/add"
id="ticketAuditerForm" method="post">
<table id="companyType_add_table" cellpadding="0" cellspacing="0">
<tr>
<th >Carrier:</th>
<td id = "ticketAuditerCarrierAddInit"></td>
</tr>
<tr>
<th>user:</th>
<td align="left">
<input id="userNameAdd" name="auditer.userName" type="text" size="20" />
<input name="search" type="button" value="select" onclick="searchUser()" />
<input id="userIdAdd" name="auditer.id" type="hidden" size="20" value="3" />
</td>
</tr>
<tr>
<td colspan="2"><p class="validateTips" align="center">...</p>
<input type="hidden" name="id" id="id" value="" />
</td>
</tr>
</table>
</form>
然后我想添加一个隐藏元素来形成:
<input type="hidden" id ="ticketTypeId" name ="ticketTypeId" value="${1}">
jquery代码:
$("#searchTicketAuditer").button().click(function() {
$("#searchTicketAuditerForm").add("#ticketTypeId");
$("#searchTicketAuditerForm").submit(); })
当我提交表单时,我可以从表单中获取ticketTypeId,请帮帮我!
答案 0 :(得分:1)
如果隐藏元素已经存在于dom中,则使用.append()
$("#searchTicketAuditer").button().click(function() {
$("#searchTicketAuditerForm").append($("#ticketTypeId"));
$("#searchTicketAuditerForm").submit(); })
答案 1 :(得分:0)
如果您的元素已经在DOM中,并且您想将其附加到表单,则可以使用
$("#searchTicketAuditerForm").append($("#ticketTypeId"));
* when you use append() that hidden button will cut and paste
如果您想要复制和粘贴,可以使用clone()
$("#ticketTypeId").clone().appendTo("#searchTicketAuditerForm");
如果DOM中没有元素,可以使用
$("#searchTicketAuditerForm").append('<input type="hidden" id ="ticketTypeId" name ="ticketTypeId" value="${1}">');