Alert for unsaved changes in form

前端 未结 7 1893
谎友^
谎友^ 2020-11-30 18:47

I want to write Jquery code in master file, so that if there if user changes page and there is any unsaved changes user should get alert. I got one answer from this: link

7条回答
  •  渐次进展
    2020-11-30 19:12

    change event is fired once the user blurs from input not on every single character inputed.

    If you need it to be called every time something is changed (even if focus is still in that input field) you would have to rely on combination of keyup and bunch of events to keep track of pasting/cuting using mouse only.

    P.S. I hope you're aware that your approach to detecting changes isn't the best one? If user input some text, leaves the field and then reverts the changes the script would still alert him about modified text.

提交回复
热议问题