我写的html,js代码为什么ie下能运行,chrome就不能运行
<!doctypehtml><html><head><metacharset="utf-8"><title>幻灯片</title></head><style>#banne...
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>幻灯片</title>
</head>
<style>
#banner-wpar{
width:520px;
height:280px;
border:1px solid blue;
overflow:hidden;
margin:0 auto;
position:relative;
}
.conter-width{
width:5000px;
position:relative;
left:0;
}
.banner-nav-left{
position:absolute;
top:120px;
left:0;
}
.banner-nav-rig{
position:absolute;
top:120px;
left:496px;
}
#banner-wpar ul{
position:absolute;
top:210px;
left:200px;
float:left;
}
#banner-wpar ul li{
float:left;
margin:17px;
}
</style>
<body>
<div id="banner-wpar">
<div class="conter-width">
<img src="1.jpg">
<img src="2.jpg">
<img src="3.jpg">
<img class="banner-nav-left" src="left.png">
<img class="banner-nav-rig" src="rig.png">
<ul >
<a href=""><li></li></a >
<a><li></li></a >
<a><li></li></a >
</ul>
</div>
</div>
<script>
var conter_width = document.getElementsByClassName('conter-width')[0];
var banner_nav_left = document.getElementsByClassName('banner-nav-left')[0];
var banner_nav_rig = document.getElementsByClassName('banner-nav-rig')[0];
var oimg = conter_width.getElementsByTagName('img')[0];
var oimgw = oimg.clientWidth;
banner_nav_left.onclick = function (){
conter_width.style.left = -oimgw+'px'
}
</script>
</body>
</html>
是哪里出了问题呢? 展开
<html>
<head>
<meta charset="utf-8">
<title>幻灯片</title>
</head>
<style>
#banner-wpar{
width:520px;
height:280px;
border:1px solid blue;
overflow:hidden;
margin:0 auto;
position:relative;
}
.conter-width{
width:5000px;
position:relative;
left:0;
}
.banner-nav-left{
position:absolute;
top:120px;
left:0;
}
.banner-nav-rig{
position:absolute;
top:120px;
left:496px;
}
#banner-wpar ul{
position:absolute;
top:210px;
left:200px;
float:left;
}
#banner-wpar ul li{
float:left;
margin:17px;
}
</style>
<body>
<div id="banner-wpar">
<div class="conter-width">
<img src="1.jpg">
<img src="2.jpg">
<img src="3.jpg">
<img class="banner-nav-left" src="left.png">
<img class="banner-nav-rig" src="rig.png">
<ul >
<a href=""><li></li></a >
<a><li></li></a >
<a><li></li></a >
</ul>
</div>
</div>
<script>
var conter_width = document.getElementsByClassName('conter-width')[0];
var banner_nav_left = document.getElementsByClassName('banner-nav-left')[0];
var banner_nav_rig = document.getElementsByClassName('banner-nav-rig')[0];
var oimg = conter_width.getElementsByTagName('img')[0];
var oimgw = oimg.clientWidth;
banner_nav_left.onclick = function (){
conter_width.style.left = -oimgw+'px'
}
</script>
</body>
</html>
是哪里出了问题呢? 展开
1个回答
展开全部
.onclick这个函数在Chrome中只有当在控制台输入才有效果,还有..你的代码之前我改的时候添加了addEventListener,这次更改一下,改成:
function left(){conter_width.style.left = -oimgw+'px'}
try{
banner_nav_left.onclick = function (){
conter_width.style.left = -oimgw+'px'
}
banner_nav_left.addEventListener('click',left);
}
catch(e){}
这样子我们的函数变成了有错误也不会报出,并且兼容IE和Chrome等,IE低版本浏览器是不支持addEventListener的
追问
嗯 还有个问题想再问问你,为什么我点击按钮,切换到第二张的时候 图片就覆盖了按钮
追答
设置z-indez即可,无效的话你进入浏览器开发者工具查看层叠即可
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询