IE与Firefox浏览器javascript小总结

2010-04-27 14:27:46 javascript Views(299)

1、获取浏览器版本
function judgeExplore()
{
if(navigator.userAgent.indexOf("Firefox")>0){
return "Firefox";
}
if(navigator.userAgent.indexOf("IE")>0){
return "IE";
}
};
2、对于表单信息trim处理。
在firefox最新版本中支持document.form.textname.value.trim(),去掉textname信息的左右空格,但在ie浏览器以及firfox的过去版本中不支持该方法。
解决方法:
function trim(str) {
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
3、不同浏览器下获取表单信息方法不同.
firefox:document.setupconfig.textname.value;
IE:     document.setupconfig.elements["textname"].value;
获取select的选定值,在ie和ff下都可用:
document.getElementById("cc").options[window.document.getElementById("cc").selectedIndex].text;
4、不同浏览器下将focus到某个表单信息方法不同.
IE:document.formname.elements['textname'].focus();
firefox:document.getElementById("textname").focus();
5、为制定的表单控件绑定背景颜色.
document.getElementById("textname").className = "backgroundColor";

Comments

Leave a Comment

Name
Content
Verification Type the characters you see in the picture below