我在表格中的每一行都有一个下拉框
<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!'); } ); });更多推荐
发布评论