为了账号安全,请及时绑定邮箱和手机立即绑定

求大神帮解答一下,为什么我写的代码,第二个按钮没有将css twov的样式附加到ID为box2上

如题,同时火狐还提示“

预期为声明,但却得到 '.'。  跳过至下一个声明。 html4.e01.html:15

搜索 声明区的闭合 } 时遇到不期望的文件结束符。

”这样的文字。谢谢

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title></title>

<style type="text/css">

.two{

border:1px solid #ccc;

width:230px;

height:50px;

background:#9CF;

color:blue;

.twov{

border:3px solid #ccc;

width:430px;

height:230px;

background:#eCF;

color:blue;

}

</style>

<script type="text/javascript">

        function odiva(){

var p1=document.getElementById("box2");

p1.className="two";

};

        function odivb(){

var p2=document.getElementById("box2");

p2.className="twov";

};


</script>

</head>

<body>

<div id="box2">

这个是一段文字内容;

</div>

<button type="button" onclick="odiva()">这个是按钮</button>

<button type="button" onclick="odivb()">第二按钮</button>


</body>

</html>


正在回答

2 回答

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title></title>

<style type="text/css">

.two{

    border:1px solid #ccc;

    width:230px;

    height:50px;

    background:#9CF;

    color:blue;

    }         //注意代码规范化,你忘了加结束符}

.twov{

    border:3px solid #ccc;

    width:430px;

    height:230px;

    background:#eCF;

    color:blue;

    }

</style>

<script type="text/javascript">

        function odiva(){

var p1=document.getElementById("box2");

p1.className="two";

};

        function odivb(){

var p2=document.getElementById("box2");

p2.className="twov";

};


</script>

</head>

<body>

<div id="box2">

这个是一段文字内容;

</div>

<button type="button" onclick="odiva()">这个是按钮</button>

<button type="button" onclick="odivb()">第二按钮</button>


</body>

</html>


0 回复 有任何疑惑可以回复我~

第一个样式没有闭合大括号

0 回复 有任何疑惑可以回复我~
#1

小东别院 提问者

嗯嗯。谢谢哈。我一直云想JS的问题了,没注意CSS那里没封闭;
2014-12-01 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

求大神帮解答一下,为什么我写的代码,第二个按钮没有将css twov的样式附加到ID为box2上

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信