代码如下。求好心的大神大大帮忙
<!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" />
<script language="javascript">
function ToRed()
{
var oDiv=document.getElementById('div1')
oDiv.className='box'
}
function Toqq()
{
var oDiv=document.getElementById('div1')
oDiv.className='box'
}
</script>
<style>
#div1 {width:900px;height:450px; border:1px;}
.box{background: #003333;}
.box2{background: #0033FF}
</style>
<title>无标题文档</title>
</head><body>
<div id="div1">
<label>
<input type="button" name="Submit" value="DD" onclick="ToRed()" />
<input type="button" name="Submit2" value="按钮" onclick="Toqq()"/>
</label>
</div>
</body>
</html>
<!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" />
<script language="javascript">
function ToRed()
{
var oDiv=document.getElementById('div1')
oDiv.className='box'
}
function Toqq()
{
var oDiv=document.getElementById('div1')
oDiv.className='box'
}
</script>
<style>
#div1 {width:900px;height:450px; border:1px;}
.box{background: #003333;}
.box2{background: #0033FF}
</style>
<title>无标题文档</title>
</head><body>
<div id="div1">
<label>
<input type="button" name="Submit" value="DD" onclick="ToRed()" />
<input type="button" name="Submit2" value="按钮" onclick="Toqq()"/>
</label>
</div>
</body>
</html>
<input type="button" name="Submit2" value="按钮" onclick="Toqq()"/>
改为
<input type="button" name="Submit" value="DD" onclick="ToRed();" />
<input type="button" name="Submit2" value="按钮" onclick="Toqq();"/>
试一试
还有oDiv是有数字开头的吗?
{
var oDiv=document.getElementById('div1')
oDiv.className='box'
}
function Toqq()
{
var oDiv=document.getElementById('div1')
oDiv.className='box'
两个函数做同一个事情有意义吗?
是不是你的浏览器把JS禁用了,开启下,开启方法百度一大堆
http://zhidao.baidu.com/question/191701015.html楼上说的两个函数一样,楼主的想法是一个用 .box,一个用.box2
{
var oDiv=document.getElementById('div1')
oDiv.className='box'
}
function Toqq()
{
var oDiv=document.getElementById('div1')
oDiv.className='box'
}
这两个函数是一样的吧,我复制运行啦一下,确实不行,有些东西是不是搞的复杂点
<!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" />
<script language="javascript">
function ToRed()
{
var oDiv=document.getElementById('div1')
oDiv.className='box'
}
function Toqq()
{
var oDiv=document.getElementById('div1')
oDiv.className='box2'
}
</script>
<style>
#div1 {width:900px;height:450px; border:1px;}
.box{background: #003333;}
.box2{background: #0033FF}
</style>
<title>无标题文档</title>
</head><body>
<div id="div1">
<label>
<input type="button" name="Submit" value="DD" onclick="ToRed()" /></label>
<label>
<input type="button" name="Submit2" value="按钮" onclick="Toqq()"/>
</label>
</div>
</body>
</html>
ToRed() 改变div1的className 为boxToqq() 改变div1的className 为box2
var oDiv=document.getElementById('div1')
oDiv.className='box'
改成
var oDiv=document.getElementById('div1');
oDiv.className='box';
试试 。有时有一个小的疏忽就导致很多问题。浪费时间,养成好习惯,编写的时候少出错。
{
var oDiv=document.getElementById('div1')
oDiv.className='box'
}
function Toqq()
{
var oDiv=document.getElementById('div1')
oDiv.className='box'
}2个className 是一样的 ?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script language="javascript">
function a1(){
var a=document.getElementById("div1");
a.className="box";
}function a2(){
var b=document.getElementById("div1");
b.className="box2";
}
</script>
<style>
#div1 {width:900px;height:450px; border:1px;}
.box{background: #003333;}
.box2{background: #0033FF}
</style>
<title>无标题文档</title>
</head>
<body>
<div id="div1">
<input type="button" value="1" onclick="a1()" /><input type="button" value="2" onclick="a2()" />
</div>
</body>
</html>