我有一个表单(id="search_options")并且我通过以下方式跟踪表单中的更改:
$("#search_options").change(function() {
// Bla Bla Bla
});
在这种形式中,我有很多输入,其中之一是 select(id="project_category"),我想捕获用户是否更改了 project_category select 或其他输入。我怎样才能做到这一点?谢谢
最佳答案
您想要做的事情可以通过我能想到的两种方式来完成。 首先,单独捕获表单中所有输入项的更改事件
$("#search_options input,#search_options select").change(function() {
// "this" is the input that has changed so you would check if it had id = "project_category" here
});
或者,您可以在每次更改时跟踪“project_category”的当前值
var current_Project_Category = "";
$("#search_options").change(function() {
if(current_Project_Category != $(this).find("#project_category").val())
{
//project category has changed so mark this as the current one
//also run any change code here
current_Project_Category = $(this).find("#project_category").val()
}
});
关于javascript - 使用 jQuery 查找更改的表单元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3001218/