為什么在點修改p2的時候沒有反應(yīng)呢?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>className屬性</title>
<style type="text/css">
? ? body{ font-size:20px;}
? ? p.one{
border:1px solid #eee;
width:230px;
height:50px;
background:#ccc;
color:red;
? ? }
p.two{
border:1px solid #ccc;
width:230px;
height:50px;
background:#9CF;
color:blue;
}
</style>
</head>
<body>
? <p id="p1" class="two">123</p>
? <input type="button" onclick="add()" value="xiugai p1">
? <p id="p2" class="one">456</p>
? <input type="button" onclick="add1()" value="xiugai p2">
? <script type="text/javascript">
? function add(){
? ? ?var p1= document.getElementById("p1");
? ? ?p1.className="one";
? }
? function add1(){
? ? ? var p2=document.getElemnetById("p2");
? ? ? p2.className="two";
? }
? </script>
??
</body>
</html>
2016-11-30
代碼打錯了
function add1(){
? ? ? var p2=document.getElemnetById("p2");
? ? ? p2.className="two";
? }