How do I know that a form input has changed?

后端 未结 5 394
温柔的废话
温柔的废话 2021-02-04 00:59

I have a form generated by <% Ajax.BeginForm() {} %> which contains a lot of inputs and texareas.

When an input value change, I need to know about it

5条回答
  •  [愿得一人]
    2021-02-04 01:31

    I would do this with jQuery. It would be something like this (just a draft, you may need to add/change some code):

    $(document).ready(function() {  
        $('#formId:input').each(function(key) {
            $(this).change(function() {
                $(this).addClass('dirty');
            });
        });
    });
    

    Then, before POSTing, check if there is a dirty input. You can even add some color by using the dirty css class.

    EDIT: typo fixed 'changed' to 'change'

提交回复
热议问题