Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

javascript - How safe/reliable/cross-browser compatible is $(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
}

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...

Any feedback greatly appreciated.

Cheers Rob

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

It is described here: https://developer.mozilla.org/en/DOM/HTMLTextAreaElement and there is no notice about compatibility issues.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...