[英]find current form and change action url and submit using jquery
在我的JSP中,我有不同的<form>
,每个<form>
都有<table>
, <th>
, <tr>
和<td>
。 当我单击<TH>
标记时,我们应该找到<form>
,更改操作URL并在JQUERY click()事件中提交。
我的代码如下:
<form>
<table>
<thead>
<tr>
<th id='th1'>th1</th>
<th id='th2'>th2</th>
<th id='th3'>th3</th>
<th id='th4'>th4</th>
<thead>
</table>
</from
<form>
<table>
<thead>
<tr>
<th id='th1'>th1</th>
<th id='th2'>th2</th>
<th id='th3'>th3</th>
<th id='th4'>th4</th>
<thead>
</table>
</from>
在这里,当我单击<th id='th1'>
,我们应该找到<form>
,更改操作URL并提交。 请你帮助我好吗?
$('th').click(function(){
var $form = $(this).parents('form');
$form.attr('action', 'new url').submit();
})
说,例如你有一个表格
<form>
<table>
<thead>
<tr>
<th id='th1'>th1</th>
<th id='th2'>th2</th>
<th id='th3'>th3</th>
<th id='th4'>th4</th>
<thead>
</table>
</from>
你可以试试
$("th").click(function(e){
var thisForm = $(this).closest("form");
thisForm.attr("action","yourAction");
thisForm.submit();
});
首先要注意HTML中的问题:
</form>
标记(它是“ form”,而不是“ from”)。 <th>
元素唯一的id
属性。 然后是这样的:
$(document).ready(function() {
$("th").click(function() {
$(this).closest("form").attr("action", this.id).submit();
});
});
您没有明确说明要将表单操作设置为什么,因此通过示例的方式,我将其设置为被单击的<th>
元素的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.