1、判断浏览器类型
1var ver="IE6";
2if (window.XMLHttpRequest)
3 ver = (!window.ActiveXObject) ? "Mozilla or Safari" : "IE7";
4return ver;
2if (window.XMLHttpRequest)
3 ver = (!window.ActiveXObject) ? "Mozilla or Safari" : "IE7";
4return ver;
2、获取位置,在firefox中,无法使用object.style.pixelLeft,只能用object.style.left (top一样) ,object.style.left 返回值是带有单位的,这里假设单位是(px),如下为获取位置的函数
1 function getPos(obj)
2 {
3 var p = new function(){this.left;this.top;};
4 p.left = parseInt(obj.style.left.slice(0,-2),10);
5 p.top = parseInt(obj.style.top.slice(0,-2),10);
6 return p;
7 }
8 var pos = getPos(document.getElementById("111"));
9 alert("left:"+pos.left+"\ntop:"+pos.top);
2 {
3 var p = new function(){this.left;this.top;};
4 p.left = parseInt(obj.style.left.slice(0,-2),10);
5 p.top = parseInt(obj.style.top.slice(0,-2),10);
6 return p;
7 }
8 var pos = getPos(document.getElementById("111"));
9 alert("left:"+pos.left+"\ntop:"+pos.top);
3、透明度设置不同
1 function setOpcity(obj,value){
2 // alpha(opacity=50)仅被IE支持
3 if(isMSIE){
4 obj.style.filter="alpha(opacity="+value+")";
5 }else{
6 obj.style.MozOpacity=value*0.01;
7 }
8 }
2 // alpha(opacity=50)仅被IE支持
3 if(isMSIE){
4 obj.style.filter="alpha(opacity="+value+")";
5 }else{
6 obj.style.MozOpacity=value*0.01;
7 }
8 }
4、禁止文本选择的方法
1、判断浏览器类型
1var ver="IE6";
2if (window.XMLHttpRequest)
3 ver = (!window.ActiveXObject) ? "Mozilla or Safari" : "IE7";
4return ver;
2if (window.XMLHttpRequest)
3 ver = (!window.ActiveXObject) ? "Mozilla or Safari" : "IE7";
4return ver;
2、获取位置,在firefox中,无法使用object.style.pixelLeft,只能用object.style.left (top一样) ,object.style.left 返回值是带有单位的,这里假设单位是(px),如下为获取位置的函数
1 function getPos(obj)
2 {
3 var p = new function(){this.left;this.top;};
4 p.left = parseInt(obj.style.left.slice(0,-2),10);
5 p.top = parseInt(obj.style.top.slice(0,-2),10);
6 return p;
7 }
8 var pos = getPos(document.getElementById("111"));
9 alert("left:"+pos.left+"\ntop:"+pos.top);
2 {
3 var p = new function(){this.left;this.top;};
4 p.left = parseInt(obj.style.left.slice(0,-2),10);
5 p.top = parseInt(obj.style.top.slice(0,-2),10);
6 return p;
7 }
8 var pos = getPos(document.getElementById("111"));
9 alert("left:"+pos.left+"\ntop:"+pos.top);
3、透明度设置不同
1 function setOpcity(obj,value){
2 // alpha(opacity=50)仅被IE支持
3 if(isMSIE){
4 obj.style.filter="alpha(opacity="+value+")";
5 }else{
6 obj.style.MozOpacity=value*0.01;
7 }
8 }
2 // alpha(opacity=50)仅被IE支持
3 if(isMSIE){
4 obj.style.filter="alpha(opacity="+value+")";
5 }else{
6 obj.style.MozOpacity=value*0.01;
7 }
8 }
4、禁止文本选择的方法
1 <script>
2 document.onselectstart=function(){return false;}//这个函数是对ie,为ff时使用css来控制
3 </script>
4 <style>
5 /*下面这个css是firefox防止选择的,firefox没有onselectstart事件*/
6 body
7 {
8 -moz-user-focus: ignore;
9 -moz-user-input: disabled;
10 -moz-user-select: none;
11 }
12
13 </style>
2 document.onselectstart=function(){return false;}//这个函数是对ie,为ff时使用css来控制
3 </script>
4 <style>
5 /*下面这个css是firefox防止选择的,firefox没有onselectstart事件*/
6 body
7 {
8 -moz-user-focus: ignore;
9 -moz-user-input: disabled;
10 -moz-user-select: none;
11 }
12
13 </style>