VaR patterns = {
Hyphen:/(-[A-Z])/I,
Root_tag:/^ body | HTML $/I
};
VaR tocamel = function (property ){
// If no-[A-Z] letter exists, return directly
If (! Patterns. hyphen. Test (property )){
Return property;
}
// If there is a cache, the replaced value is directly returned.
If (propertycache [property]) {
Return propertycache [property];
}
// Use regular expression replacement
VaR converted = property;
While (patterns.hyphen.exe C (converted )){
Converted = converted. Replace (Regexp. $1,
Regexp. $1. substr (1). touppercase ());
}
// Save to cache
Propertycache [property] = converted;
Return converted;
}; In Yahoo. util. Dom, The getstyle function considers more compatibility issues with different browsers,CodeAs follows:
// Use W3C Dom standard browsers, such as Firefox, opera, and Safari
If (document. defaultview & document. defaultview. getcomputedstyle ){
Getstyle = function (El, property ){
VaR value = NULL;
// Rename some CSS style names
If (property = 'float '){
Property = 'cssfloat ';
}
// Obtain the attributes added with CSS.
VaR computed = Document. defaultview. getcomputedstyle (El ,'');
If (computed ){
Value = computed [tocamel (property)];
}
return el. style [property] | value;
};
// if it is an IE browser
} else if (document.doc umentelement. currentstyle & isie) {
getstyle = function (El, property) {
switch (tocamel (property )) {
// the name of "Conversion" is something that IE can recognize
case 'opacity ':
var val = 100;
try {
val =
el. filters ['dximagetransform. microsoft. alpha ']. opacity;
}catch (e) {
try {
val = el. fi Lters ('alpha '). opacity;
}catch (e) {
}< BR >}< br> // percentage
return Val/100;
case 'float':
property = 'stylefloat';
default:
VaR value = el. currentstyle? El. currentstyle [property]: NULL;
return (El. style [property] | value);
}< BR> };
} else {
// obtain the inline style
getstyle = function (El, property) {return el. style [property] ;};< BR >}in addition, PPK's elaborate on getstyle on his blog is also wonderful. If you are interested, you can check it out.