$(this)[0] .defaultValue如何安全/可靠/跨浏览器兼容 [英] How safe/reliable/cross-browser compatible is $(this)[0].defaultValue
问题描述
对于使用$(this)[0] .defaultValue来确定文本框值是否与原始值相比有所变化,我将不胜感激.
I would appreciate some feedback regarding the use of $(this)[0].defaultValue for determining whether a textbox value has change from the original value e.g.
//keyUp event
if($(this)[0].defaultValue != $(this).val())
{
//Field has been modified mark as dirty
}
在Chrome中,从defaultValue始终是文本框加载到DOM中的原始值的意义上来说,似乎可以生成所需的输出.但是,直到在Chrome Dev工具中搜寻DOM对象以寻找完全不同的东西之后,我才才发现此值,我担心它可能会带来很多问题.此外,Google并没有引起太多关注,这让我更加担忧...
In Chrome it seems to generate the desired output in the sense that the defaultValue is always the original value the textbox was loaded into the DOM with. However I have only recently discovered this value after crawling through DOM objects in the Chrome Dev tools looking for something completely different and I am concerned that it may come with a whole heap of problems. Additionally Google didn't turn much up which concerns me even more...
任何反馈都非常感谢.
欢呼 罗布
推荐答案
这似乎很安全.我只是使用了这个小提琴: http://jsfiddle.net/rXsrQ/并在chrome/firefox 3.6上对其进行了测试/safari 4/ie8,它们的行为都相同.
It seems pretty safe. i just used this fiddle: http://jsfiddle.net/rXsrQ/ and tested it across chrome/firefox 3.6/safari 4/ ie8, they all behave the same.
在此处进行了描述: https://developer.mozilla.org/en/DOM/HTMLTextAreaElement ,并且没有有关兼容性问题的通知.
It is described here: https://developer.mozilla.org/en/DOM/HTMLTextAreaElement and there is no notice about compatibility issues.
在此也进行了描述: http://msdn.microsoft.com/zh-CN/library/ms533718(v=vs.85).aspx 似乎与ie 5及更高版本兼容,所以我似乎不明白为什么不应该这样使用安全.
It is also described here: http://msdn.microsoft.com/en-us/library/ms533718(v=vs.85).aspx and seems to be compatible with ie 5 and up, so i don't seem why it shouldn't be safe to use.
这篇关于$(this)[0] .defaultValue如何安全/可靠/跨浏览器兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!