i have a form(id="search_options") and i tracking cha开发者_如何学运维nges in form by:
$("#search_options").change(function() {
// Bla Bla Bla
});
In this form i have many inputs and one of is select(id="project_category") and i want to catch if user changed project_category select or another input. How can i done this ? Thanks
What you are looking to do could be accomplished 2 ways I can think of off the top of my head. First, Capture the change event for all input items in your form individually
$("#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
});
Alternatively you could track the current value of the "project_category" on every change
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()
}
});
There is a plugin made for exactly this purpose:
jQuery Form Observe
This plugin observes values of form elements. When end-user changes any values of input elements, observer shows which values were changed. And observer also alerts to users when they try to move out from the page before submitting changes.
Try this instead:
$("#search_options").find('input,select').change(function() {
var changedId = $(this).attr('id');
var newVal = $(this).val();
});
精彩评论