Detecting data changes in forms using jQuery

后端 未结 10 2040
遇见更好的自我
遇见更好的自我 2020-12-05 13:27

I\'m using ASP.NET 2.0 with a Master Page, and I was wondering if anyone knew of a way to detect when the fields within a certain

or fieldset<
10条回答
  •  一个人的身影
    2020-12-05 14:08

    You could bind the Change event for all inputs and flag a variable as true. Like this.

    var somethingChanged = false;
    $(document).ready(function() { 
       $('input').change(function() { 
            somethingChanged = true; 
       }); 
    });
    

    But, keep in mind that if the user changes something, then changes back to the original values, it will still be flagged as changed.

    UPDATE: For a specific div or fieldset. Just use the id for the given fieldset or div. Example:

    var somethingChanged = false;
    $(document).ready(function() { 
       $('#myDiv input').change(function() { 
            somethingChanged = true; 
       }); 
    });
    

提交回复
热议问题