gpt4 book ai didi

JQuery 根据条件选择元素

转载 作者:行者123 更新时间:2023-12-01 07:36:15 25 4
gpt4 key购买 nike

表格内的每一行都有一个下拉框

<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端可以捕获哪一行的下拉框触发事件?

最佳答案

当您使用 jQuery.post/get 时,您可以在每个选择上放置一个 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!');
}

);
});

关于JQuery 根据条件选择元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1377245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com