點擊按鈕樣式不斷切換,下面的文字也會自動變,這是我花了十小時琢磨出來的
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>className屬性</title>
<style type="text/css">
? ?.one{background-color:red;}
? ?.two{background-color:blue;}
</style>
</head>
<body>
? ? <p2 id="mama" class="one">javascript</p2><br/>
? ? <form>
? ? <input type="button" value="點擊更改" onclick="lala()">
? ? </form>
? ? <p id="aa">P元素Class值為:one</p>
? ? <script type="text/javascript">
? ? ? ? var mychar=document.getElementById("mama");
? ? ? ? var aa=document.getElementById("aa");
? ? ? ? function lala(){
? ? ? ? ? ? if(mychar.className=="one")
? ? ? ? ? ? {mychar.className="two";}
? ? ? ? ? ? else{mychar.className="one";}
? ? ? ? ? ? aa.innerHTML=("P元素Class值為:"+mychar.className+"<br>")
? ? ? ? ?}
? ? </script>
</body>
</html>
2019-08-27
第一個p標簽多寫了個2喲
2019-08-27
你的命名方法治好了我每次想半天名字的毛病? 贊?
2019-08-27
GB2312字符集呢?我說打開亂碼
2019-08-24
哈哈,你寫的太好了,我就學習一下
2019-08-24
?
?function lala(){
? ? ? ? ? ? if(mychar.className=="one"){
mychar.className="two";
}else{
mychar.className="one";
? ? ? ? ? ? }
? ? ? ? ? ? ?aa.innerHTML=("P元素Class值為:"+mychar.className+"<br>");
? ? ? ? }
把函數里面改一點就行