求一个IE6下兼容浮动层不随滚动条滚动,就像广告联那样 用了个floatdiv插件试了下,在IE6下报错,求个在IE6兼容的谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 IE6 老了,建议去换个IE8或是IE7. Ie6毛病多~ 在IE6下可以执行,但是就是报错,显示缺少对象$("#id").floatdiv({left:"10px",top:"10px"});以上参数,设置浮动层在left 10个像素,top 10个像素的位置*/jQuery.fn.floatdiv=function(location){ //判断浏览器版本 var IE6=false; var Sys = {}; var ua = navigator.userAgent.toLowerCase(); var s; (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : 0; if(Sys.ie && Sys.ie=="6.0"){ IE6=true; } var windowWidth,windowHeight;//窗口的高和宽 //取得窗口的高和宽 if (self.innerHeight) { windowWidth=self.innerWidth; windowHeight=self.innerHeight; }else if (document.documentElement&&document.documentElement.clientHeight) { windowWidth=document.documentElement.clientWidth; windowHeight=document.documentElement.clientHeight; } else if (document.body) { windowWidth=document.body.clientWidth; windowHeight=document.body.clientHeight; } return this.each(function(){ var loc;//层的绝对定位位置 var wrap=$("<div></div>"); var top=-1; if(location==undefined || location.constructor == String){ switch(location){ case("rightbottom")://右下角 loc={right:"0px",bottom:"0px"}; break; case("leftbottom")://左下角 loc={left:"0px",bottom:"0px"}; break; case("lefttop")://左上角 loc={left:"0px",top:"0px"}; top=0; break; case("righttop")://右上角 loc={right:"0px",top:"0px"}; top=0; break; case("middletop")://居中置顶 loc={left:windowWidth/2-$(this).width()/2+"px",top:"0px"}; top=0; break; case("middlebottom")://居中置低 loc={left:windowWidth/2-$(this).width()/2+"px",bottom:"0px"}; break; case("leftmiddle")://左边居中 loc={left:"0px",top:windowHeight/2-$(this).height()/2+"px"}; top=windowHeight/2-$(this).height()/2; break; case("rightmiddle")://右边居中 loc={right:"0px",top:windowHeight/2-$(this).height()/2+"px"}; top=windowHeight/2-$(this).height()/2; break; case("middle")://居中 var l=0;//居左 var t=0;//居上 l=windowWidth/2-$(this).width()/2; t=windowHeight/2-$(this).height()/2; top=t; loc={left:l+"px",top:t+"px"}; break; default://默认为右下角 location="rightbottom"; loc={right:"0px",bottom:"0px"}; break; } }else{ loc=location; var str=loc.top; //09-11-5修改:加上top为空值时的判断 if (typeof(str)!== undefined){ str=str.replace("px",""); top=str; } } /*fied ie6 css hack*/ if(isIE6){ if (top>=0) { wrap=$("<div style=\"top:expression(documentElement.scrollTop+"+top+");\"></div>"); }else{ wrap=$("<div style=\"top:expression(documentElement.scrollTop+documentElement.clientHeight-this.offsetHeight);\"></div>"); } } $("body").append(wrap); wrap.css(loc).css({position:"fixed", z_index:"999"}); if (isIE6) { wrap.css("position","absolute"); //没有加这个的话,ie6使用表达式时就会发现跳动现象 //至于为什么要加这个,还有为什么要加nothing.txt这个,偶也不知道,希望知道的同学可以告诉我 $("body").css("background-attachment","fixed").css("background-image","url(n1othing.txt)"); } //将要固定的层添加到固定层里 $(this).appendTo(wrap); });}; 这样的可以吗<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312"> <title> new document </title> <meta name="keywords" content=""> <meta name="description" content=""> </head> <body> <div id="" style="height:1500px;"></div> <div id="kk" style="border:1px solid #f00;width:200px; height:35px; top:300px; position:absolute;">左边对联</div> <script type="text/javascript"> <!--function newtoponload() { var c = document.getElementById("kk"); function b() { var a = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop; setTimeout(function(){c.style.top = (300 + a) + "px"},160); } window.onscroll = b; b()}if (window.attachEvent) { window.attachEvent("onload", newtoponload)} else { window.addEventListener("load", newtoponload, false)} //--> </script> </body></html> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="content-type" content="text/html; charset=gb2312"><title> new document </title></head><body><div id="" style="height:1000px;"></div><div id="left" style="border:1px solid #f00;width:100px; height:200px; top:100px; left:5px; position:absolute;">左边对联</div><div id="right" style="border:1px solid #f00;width:100px; height:200px; top:100px; right:5px; position:absolute;">右边对联</div></body></html>固定了 。 求一正则表达式,匹配由3位数字3位字母组成的字符串,数字和字母可任意排列 如何用js验证日期输入格式必须为" 1974-12-03" IE解析XML的问题,请高手解答 一个页面传值的问题!着急 为防止重复提交.按钮变灰了,但 CGI脚本读取不到值(在线等) 页面的宽度和高度怎么获取?(请大家回答一下了,不要因为太简单) 检测URL的正则表达式无法工作, 大家来快帮忙呀.. 如何给日期控件赋初植? 如何实现一打开页面光标就自动在输入框,不用鼠标去点 表格的打印预览问题 jquery ajax success 循环问题。 javascript操作cookie
在IE6下可以执行,但是就是报错,显示缺少对象
$("#id").floatdiv({left:"10px",top:"10px"});
以上参数,设置浮动层在left 10个像素,top 10个像素的位置
*/
jQuery.fn.floatdiv=function(location){
//判断浏览器版本
var IE6=false;
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : 0;
if(Sys.ie && Sys.ie=="6.0"){
IE6=true;
}
var windowWidth,windowHeight;//窗口的高和宽
//取得窗口的高和宽
if (self.innerHeight) {
windowWidth=self.innerWidth;
windowHeight=self.innerHeight;
}else if (document.documentElement&&document.documentElement.clientHeight) {
windowWidth=document.documentElement.clientWidth;
windowHeight=document.documentElement.clientHeight;
} else if (document.body) {
windowWidth=document.body.clientWidth;
windowHeight=document.body.clientHeight;
}
return this.each(function(){
var loc;//层的绝对定位位置
var wrap=$("<div></div>");
var top=-1;
if(location==undefined || location.constructor == String){
switch(location){
case("rightbottom")://右下角
loc={right:"0px",bottom:"0px"};
break;
case("leftbottom")://左下角
loc={left:"0px",bottom:"0px"};
break;
case("lefttop")://左上角
loc={left:"0px",top:"0px"};
top=0;
break;
case("righttop")://右上角
loc={right:"0px",top:"0px"};
top=0;
break;
case("middletop")://居中置顶
loc={left:windowWidth/2-$(this).width()/2+"px",top:"0px"};
top=0;
break;
case("middlebottom")://居中置低
loc={left:windowWidth/2-$(this).width()/2+"px",bottom:"0px"};
break;
case("leftmiddle")://左边居中
loc={left:"0px",top:windowHeight/2-$(this).height()/2+"px"};
top=windowHeight/2-$(this).height()/2;
break;
case("rightmiddle")://右边居中
loc={right:"0px",top:windowHeight/2-$(this).height()/2+"px"};
top=windowHeight/2-$(this).height()/2;
break;
case("middle")://居中
var l=0;//居左
var t=0;//居上
l=windowWidth/2-$(this).width()/2;
t=windowHeight/2-$(this).height()/2;
top=t;
loc={left:l+"px",top:t+"px"};
break;
default://默认为右下角
location="rightbottom";
loc={right:"0px",bottom:"0px"};
break;
}
}else{
loc=location;
var str=loc.top;
//09-11-5修改:加上top为空值时的判断
if (typeof(str)!== undefined){
str=str.replace("px","");
top=str;
}
}
/*fied ie6 css hack*/
if(isIE6){
if (top>=0)
{
wrap=$("<div style=\"top:expression(documentElement.scrollTop+"+top+");\"></div>");
}else{
wrap=$("<div style=\"top:expression(documentElement.scrollTop+documentElement.clientHeight-this.offsetHeight);\"></div>");
}
}
$("body").append(wrap);
wrap.css(loc).css({position:"fixed",
z_index:"999"});
if (isIE6)
{
wrap.css("position","absolute");
//没有加这个的话,ie6使用表达式时就会发现跳动现象
//至于为什么要加这个,还有为什么要加nothing.txt这个,偶也不知道,希望知道的同学可以告诉我
$("body").css("background-attachment","fixed").css("background-image","url(n1othing.txt)");
}
//将要固定的层添加到固定层里
$(this).appendTo(wrap);
});
};
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title> new document </title>
<meta name="keywords" content="">
<meta name="description" content="">
</head> <body>
<div id="" style="height:1500px;"></div>
<div id="kk" style="border:1px solid #f00;width:200px; height:35px; top:300px; position:absolute;">左边对联</div>
<script type="text/javascript">
<!--
function newtoponload() {
var c = document.getElementById("kk");
function b() {
var a = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
setTimeout(function(){c.style.top = (300 + a) + "px"},160);
} window.onscroll = b;
b()
}
if (window.attachEvent) {
window.attachEvent("onload", newtoponload)
} else {
window.addEventListener("load", newtoponload, false)
}
//-->
</script>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title> new document </title>
</head><body>
<div id="" style="height:1000px;"></div>
<div id="left" style="border:1px solid #f00;width:100px; height:200px; top:100px; left:5px; position:absolute;">左边对联</div>
<div id="right" style="border:1px solid #f00;width:100px; height:200px; top:100px; right:5px; position:absolute;">右边对联</div>
</body>
</html>固定了 。