求大神幫解答一下,為什么我寫的代碼,第二個按鈕沒有將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>
2014-12-24
<!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>
2014-12-01
第一個樣式沒有閉合大括號