function toGreen(){
oDiv.style.height="300px";
oDiv.style.background="green";
}
function toRed(){
oDiv.style.width="100px";
oDiv.style.height="100px";
oDiv.style.background="red";
}
他們的最終效果是一樣的,你可以把js魅力01更改一下,效果是一樣。
body{
background:black;
}
input{
width:200px;
height:100px;
background:yellow;
}
css2.css
body{
background:#999;
}
input{
width:100px;
height:50px;
background:red;
}
網頁內容是:
<!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=utf-8" />
<title>js特效</title>
<link id="link1" rel="stylesheet" type="text/css" href="css1.css" />
</head>
<script>
function fu1(){
var oDiv=document.getElementById("link1");
oDiv.href="css1.css";
}
function fu2(){
var oDiv=document.getElementById("link1");
oDiv.href="css2.css";
}
</script>
<body>
<input type="button" value="皮膚1" onclick="fu1()"/>
<input type="button" value="皮膚2" onclick="fu2()"/>
</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=utf-8" />
<title>js特效</title>
<!-- <link id="link1" rel="stylesheet" type="text/css" href="css1.css" />-->
</head>
<script>
function setText(){
var oDiv=document.getElementById("txt1");
oDiv.value="123456789";
}
</script>
<body>
<input type="text" value="aaaa" id="txt1"/>
<input type="button" value="點擊改變文字框內容" onclick="setText()"/>
</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=utf-8" />
<title>js特效</title>
<!-- <link id="link1" rel="stylesheet" type="text/css" href="css1.css" />-->
</head>
<script>
function showHide(){
var oDiv=document.getElementById("div1");
if(oDiv.style.display=="block"){
oDiv.style.display='none';
}
else{
oDiv.style.display='block';
}
}
</script>
<style>
#div1{
width:100px;
height:200px;
background:#F00;
display:none;
}
</style>
<body>
<input type="button" value="顯示隱藏" onclick="showHide()"/>
<div id="div1"></div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js特效</title>
<!-- <link id="link1" rel="stylesheet" type="text/css" href="css1.css" />-->
</head>
<script>
function toRed(){
var oDiv=document.getElementById("div1");
oDiv.className='box';
}
</script>
<style>
#div1{
width:100px;
height:100px;
border:1px solid black;
}
.box{
background:red;
}
</style>
<body>
<input type="button" value="改變div顏色" onclick="toRed()"/>
<div id="div1"></div>
</body>
</html>