页面上有个按钮 点击按钮修改一个标签的类名
if(i == 1)
{
obj.classname = "state1";
i = 2;}
else
{
obj.classname = "state2";
}
state1 和state2 只是切换背景图片而已。但却没有实现这个效果。 ie6.0和ie7.0下正常.只是什么情况呢?如何解决?
if(i == 1)
{
obj.classname = "state1";
i = 2;}
else
{
obj.classname = "state2";
}
state1 和state2 只是切换背景图片而已。但却没有实现这个效果。 ie6.0和ie7.0下正常.只是什么情况呢?如何解决?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<style>
.state1{color:red;background:url(http://www.baidu.com/img/baidu_sylogo1.gif);}
.state2{color:green;background:url(http://csdnimg.cn/www/images/csdnindex_logo.gif);}
</style>
<script type="text/javascript" language="javascript">
var i = 1;
function test1(obj){
if(i == 1)
{
obj.className = "state1";
i = 2;
}
else
{
obj.className = "state2";
i=1;
}
}
</script>
</head>
<body>
<div onclick="test1(this)" style="width:300px;height:300px;margin:auto;border:solid 1px black;cursor:pointer;backgroud:url(http://www.baidu.com/img/baidu_sylogo1.gif);">AA</div>
</body>
</html>
没办法测试IE6、7
其实就是className大小写和obj.classname = "state2";后面接一个i=1;
就是前面两位说的,我综合了一下而已。
一开始还以为是个奇怪的问题,写出来才发现不是什么问题。