表中的每一行都有一个下拉框
<table>
<tr>
<th>
<select name="priorityID" id="priorityID">
<option label="Important" value="1" selected="selected">Important</option>
<option label="semi important" value="2">semi important</option>
<option label="normal" value="3">normal</option>
<option label="not important" value="4">not important</option>
</select>
</th>
</tr>
<tr>
<th>
<select name="priorityID" id="priorityID">
<option label="Important" value="1" selected="selected">Important</option>
<option label="semi important" value="2">semi important</option>
<option label="normal" value="3">normal</option>
<option label="not important" value="4">not important</option>
</select>
</th> 现在的问题是,每当priorityID发生变化时,我都需要调用一个JQuery函数来更新数据库。现在,由于每一行都有自己的下拉框,如何以这样一种方式编写JQuery :在JQuery端,它可以捕获触发事件的哪一行的下拉框?
发布于 2009-09-04 04:55:44
在使用jQuery.post/get时,您可以在每个select上放置一个ID,并将其作为数据值包含在内。
然后,您可以在服务器站点上获取它,以找出更改了哪个选择框。
<select name="priorityID" id="1">
<select name="priorityID" id="2">
<select name="priorityID" id="3">
$("select").change(function() {
$.post(
"http://api.url.com/method",
{
"selectId" : $(this).attr('id'),
"selectedValue" : $(this).val()
},
function(data) {
alert('Back!');
}
);
});发布于 2009-09-04 04:50:09
您可以将change事件与一些radness一起使用:
$("select").change(function() {
var offset = $(this).closest("tr").prevAll().length;
alert(offset);
});https://stackoverflow.com/questions/1377245
复制相似问题