在我的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并提交它。你能帮帮我吗?
发布于 2012-02-09 14:07:47
$('th').click(function(){
var $form = $(this).parents('form');
$form.attr('action', 'new url').submit();
})Here is an example
发布于 2012-02-09 14:05:47
假设你有一张表格
<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();
});发布于 2012-02-09 14:10:55
首先要注意HTML中的问题:
</form>标记(它是"form",而不是“from”)。<th>元素提供唯一的id属性。然后如下所示:
$(document).ready(function() {
$("th").click(function() {
$(this).closest("form").attr("action", this.id).submit();
});
});您没有明确说明要将表单的操作设置为什么,因此作为示例,我将其设置为所单击的<th>元素的id。
https://stackoverflow.com/questions/9206125
复制相似问题