检测实际的表格变化? [英] Detect actual form change?

查看:73
本文介绍了检测实际的表格变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有现成的方法(可能在其中一个框架中)来检测表单与原始值相比是否已更改

Is there a ready-made way (maybe in one of the frameworks) to detect whether a form has changed compared to its original values?

onchange事件不会发生,因为无论实际更改如何都会触发(例如,我可以勾选一个复选框,然后再关闭两次onchange事件)。

The onchange event won't do, because it fires regardless of actual change (I could for example tick a checkbox on, and off again, with two onchange events).

最后一种方法是将每个元素的原始值存储在隐藏字段中,然后遍历每个元素。如果有更快的方法,我会很高兴听到它!

The last resort would be to store each element's original value in a hidden field, and go through each one. If there is a faster method, I'd be happy to hear about it!

推荐答案

我不知道任何DOM检测对子/后代元素的值属性所做的更改的事件,但它应足以比较序列化之前/之后的值, $('form')。serialize()。如果您已经特别了解此方法,我很抱歉,我假设您手动浏览表单元素并将值附加到字符串。

I'm not aware of any DOM event that detects changes made to children/descendant elements' value attributes, but it should be enough to compare the serialized values before/after, $('form').serialize(). I apologize if you already knew about this method specifically, I'm assuming you're manually going through form elements and appending values to a string.

这篇关于检测实际的表格变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆