js代码在IE中能正常运行,在Firefox中却无法运行!
我是刚刚工作的菜鸟,公司用js代码控制div的display属性,我写了段代码如下:<scriptlanguage="javascript">functiona(div1...
我是刚刚工作的菜鸟,公司用js代码控制div的display属性,我写了段代码如下:
<script language="javascript">
function a(div1) {
div1.style.display = "block";
div2.style.display = "none";
div3.style.display = "none";
div4.style.display = "none";
}
function b(div2) {
div1.style.display = "none";
div2.style.display = "block";
div3.style.display = "none";
div4.style.display = "none";
}
function c(div3) {
div1.style.display = "none";
div2.style.display = "none";
div3.style.display = "block";
div4.style.display = "none";
}
function d(div4) {
div1.style.display = "none";
div2.style.display = "none";
div3.style.display = "none";
div4.style.display = "block";
}
</script>
<div style="width:100%; height:50px;">
<div style="width:20%; height:50px; background-color:Yellow; float:left;" onclick="a(div1);">
</div>
<div style="width:20%; height:50px; background-color:Red; float:left; " onclick="b(div2);">
</div>
<div style="width:20%; height:50px; background-color:Green; float:left;" onclick="c(div3);" >
</div>
<div style="width:20%; height:50px; background-color:Blue; float:left;" onclick="d(div4);">
</div>
<div style=" display:none;" id="div1">
<img src="1.jpg" />
</div >
<div style="display:none;" id="div2">
<img src="2.jpg" />
</div>
<div style="display:none;" id="div3">
<img src="3.jpg" />
</div>
<div style="display:none;" id="div4">
<img src="4.jpg" />
</div>
</div>
这段代码在IE中能正常显示,但客户要求在Firefox下也能正常运行,我试了很多方法,但还是不行!希望高手能帮忙指点一下! 展开
<script language="javascript">
function a(div1) {
div1.style.display = "block";
div2.style.display = "none";
div3.style.display = "none";
div4.style.display = "none";
}
function b(div2) {
div1.style.display = "none";
div2.style.display = "block";
div3.style.display = "none";
div4.style.display = "none";
}
function c(div3) {
div1.style.display = "none";
div2.style.display = "none";
div3.style.display = "block";
div4.style.display = "none";
}
function d(div4) {
div1.style.display = "none";
div2.style.display = "none";
div3.style.display = "none";
div4.style.display = "block";
}
</script>
<div style="width:100%; height:50px;">
<div style="width:20%; height:50px; background-color:Yellow; float:left;" onclick="a(div1);">
</div>
<div style="width:20%; height:50px; background-color:Red; float:left; " onclick="b(div2);">
</div>
<div style="width:20%; height:50px; background-color:Green; float:left;" onclick="c(div3);" >
</div>
<div style="width:20%; height:50px; background-color:Blue; float:left;" onclick="d(div4);">
</div>
<div style=" display:none;" id="div1">
<img src="1.jpg" />
</div >
<div style="display:none;" id="div2">
<img src="2.jpg" />
</div>
<div style="display:none;" id="div3">
<img src="3.jpg" />
</div>
<div style="display:none;" id="div4">
<img src="4.jpg" />
</div>
</div>
这段代码在IE中能正常显示,但客户要求在Firefox下也能正常运行,我试了很多方法,但还是不行!希望高手能帮忙指点一下! 展开
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
</style>
</head>
<body>
<script language="javascript">
var divs = ['div1', 'div2', 'div3', 'div4', ];//可以自定义
function divClick(divId) {
for(key in divs){
if(divId == divs[key]) {
document.getElementById(divId).style.display = 'block';
} else {
document.getElementById(divs[key]).style.display = 'none';
}
}
}
//FF不支持直接使用id指向节点对象,所以需要兼容浏览器并要具体指向节点对象,使用getElementById
//注意:使用.style.display的形式才能更好地兼容
//本代码 IE 和 GG 都测试通过了
//本代码可以进一步优化,使用监听、js绑定事件等方式
</script>
<div style="width:100%; height:50px;">
<div style="width:20%; height:50px; background-color:Yellow; float:left;" onclick="divClick('div1')">
gg
</div>
<div style="width:20%; height:50px; background-color:Red; float:left; " onclick="divClick('div2')">
jj
</div>
<div style="width:20%; height:50px; background-color:Green; float:left;" onclick="divClick('div3')" >
ghg
</div>
<div style="width:20%; height:50px; background-color:Blue; float:left;" onclick="divClick('div4')">
dsfe
</div>
<div style=" display:none;" id="div1">
<img src="1.jpg" />
111这是外加进去的,使用时请清理!
</div >
<div style="display:none;" id="div2">
<img src="2.jpg" />
222这是外加进去的,使用时请清理!
</div>
<div style="display:none;" id="div3">
<img src="3.jpg" />
33这是外加进去的,使用时请清理!
</div>
<div style="display:none;" id="div4">
<img src="4.jpg" />
444这是外加进去的,使用时请清理!
</div>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
</style>
</head>
<body>
<script language="javascript">
var divs = ['div1', 'div2', 'div3', 'div4', ];//可以自定义
function divClick(divId) {
for(key in divs){
if(divId == divs[key]) {
document.getElementById(divId).style.display = 'block';
} else {
document.getElementById(divs[key]).style.display = 'none';
}
}
}
//FF不支持直接使用id指向节点对象,所以需要兼容浏览器并要具体指向节点对象,使用getElementById
//注意:使用.style.display的形式才能更好地兼容
//本代码 IE 和 GG 都测试通过了
//本代码可以进一步优化,使用监听、js绑定事件等方式
</script>
<div style="width:100%; height:50px;">
<div style="width:20%; height:50px; background-color:Yellow; float:left;" onclick="divClick('div1')">
gg
</div>
<div style="width:20%; height:50px; background-color:Red; float:left; " onclick="divClick('div2')">
jj
</div>
<div style="width:20%; height:50px; background-color:Green; float:left;" onclick="divClick('div3')" >
ghg
</div>
<div style="width:20%; height:50px; background-color:Blue; float:left;" onclick="divClick('div4')">
dsfe
</div>
<div style=" display:none;" id="div1">
<img src="1.jpg" />
111这是外加进去的,使用时请清理!
</div >
<div style="display:none;" id="div2">
<img src="2.jpg" />
222这是外加进去的,使用时请清理!
</div>
<div style="display:none;" id="div3">
<img src="3.jpg" />
33这是外加进去的,使用时请清理!
</div>
<div style="display:none;" id="div4">
<img src="4.jpg" />
444这是外加进去的,使用时请清理!
</div>
</div>
</body>
</html>
展开全部
您好!很高兴为您答疑!
火狐下您可以安装Firebug检查页面代码,错误部分会有提示。它集HTML查看和编辑、Javascript控制台、网络状况监视器于一体,是开发JavaScript、CSS、HTML和Ajax的得力助手。
您可以在火狐社区了解更多内容。希望我的回答对您有所帮助,如有疑问,欢迎继续在本平台咨询。
火狐下您可以安装Firebug检查页面代码,错误部分会有提示。它集HTML查看和编辑、Javascript控制台、网络状况监视器于一体,是开发JavaScript、CSS、HTML和Ajax的得力助手。
您可以在火狐社区了解更多内容。希望我的回答对您有所帮助,如有疑问,欢迎继续在本平台咨询。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码不规范:
<script type="text/javascript">
function a(div1) {
div1.style.display = "block";
div2.style.display = "none";
div3.style.display = "none";
div4.style.display = "none";
}
function b(div2) {
div1.style.display = "none";
div2.style.display = "block";
div3.style.display = "none";
div4.style.display = "none";
}
function c(div3) {
div1.style.display = "none";
div2.style.display = "none";
div3.style.display = "block";
div4.style.display = "none";
}
function d(div4) {
div1.style.display = "none";
div2.style.display = "none";
div3.style.display = "none";
div4.style.display = "block";
}
</script>
<div style="width: 100%; height: 50px;">
<div style="width: 20%; height: 50px; background-color: Yellow; float: left;" onclick="javascript:a(document.getElementById('div1'));">
</div>
<div style="width: 20%; height: 50px; background-color: Red; float: left;" onclick="javascript:b(document.getElementById('div2'));">
</div>
<div style="width: 20%; height: 50px; background-color: Green; float: left;" onclick="javascript:c(document.getElementById('div3'));">
</div>
<div style="width: 20%; height: 50px; background-color: Blue; float: left;" onclick="javascript:d(document.getElementById('div4'));">
</div>
<div style="display: none;" id="div1">
<img src="1.jpg" />
</div>
<div style="display: none;" id="div2">
<img src="2.jpg" />
</div>
<div style="display: none;" id="div3">
<img src="3.jpg" />
</div>
<div style="display: none;" id="div4">
<img src="4.jpg" />
</div>
</div>
<script type="text/javascript">
function a(div1) {
div1.style.display = "block";
div2.style.display = "none";
div3.style.display = "none";
div4.style.display = "none";
}
function b(div2) {
div1.style.display = "none";
div2.style.display = "block";
div3.style.display = "none";
div4.style.display = "none";
}
function c(div3) {
div1.style.display = "none";
div2.style.display = "none";
div3.style.display = "block";
div4.style.display = "none";
}
function d(div4) {
div1.style.display = "none";
div2.style.display = "none";
div3.style.display = "none";
div4.style.display = "block";
}
</script>
<div style="width: 100%; height: 50px;">
<div style="width: 20%; height: 50px; background-color: Yellow; float: left;" onclick="javascript:a(document.getElementById('div1'));">
</div>
<div style="width: 20%; height: 50px; background-color: Red; float: left;" onclick="javascript:b(document.getElementById('div2'));">
</div>
<div style="width: 20%; height: 50px; background-color: Green; float: left;" onclick="javascript:c(document.getElementById('div3'));">
</div>
<div style="width: 20%; height: 50px; background-color: Blue; float: left;" onclick="javascript:d(document.getElementById('div4'));">
</div>
<div style="display: none;" id="div1">
<img src="1.jpg" />
</div>
<div style="display: none;" id="div2">
<img src="2.jpg" />
</div>
<div style="display: none;" id="div3">
<img src="3.jpg" />
</div>
<div style="display: none;" id="div4">
<img src="4.jpg" />
</div>
</div>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询