How do I know that a form input has changed?

后端 未结 5 474
温柔的废话
温柔的废话 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:55

    You could use jquery plugin dirrty for identifying form dirty.

    https://github.com/rubentd/dirrty

    In on("dirty") event set some global variable to true to identify form has changed.

    Handle window.onbeforeunload or $(window).unload() event and get confirmation from user based on that variable value.

    The advantage of this plugin is you can track back if form is changed to original values again using 'on("clean") event

提交回复
热议问题