<一>初探js特效魅力之div顯示隱藏變色02

來源:互聯網
上載者:User

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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.