JQuery选择基于标准的元素(JQuery Select Element Based On Criteria)

编程入门 行业动态 更新时间:2024-10-28 20:17:11
JQuery选择基于标准的元素(JQuery Select Element Based On Criteria)

我在表格中的每一行都有一个下拉框

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

I have a drop down box for each row inside a table

<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>

The issue is now whenever the priorityID changes, I need to call a JQuery function to update the database. Now since each row has its own drop down box, how to write the JQuery in such a manner that at the JQuery side, it can capture which row's drop down box firing the event?

最满意答案

您可以在每个选择上放置一个ID,并在使用jQuery.post/get时将其作为数据值包含在内。

然后,您可以在服务器站点获取它以确定哪些选择框已更改。

<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!'); } ); });

You can place an ID on each select and include it as a data value when you are using jQuery.post/get.

You can then get it at the server-site to figure out what select-box got changed.

<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!'); } ); });

更多推荐

本文发布于:2023-08-03 23:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405232.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   标准   JQuery   Select   Criteria

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!