日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用js实现换肤功能

發(fā)布時間:2023/12/10 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用js实现换肤功能 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

Skin.html

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>網(wǎng)頁煥膚</title>

<style type="text/css">

#main

{

?????? width:800px;

?????? height:600px;

?????? margin:auto;

?????? font-family:"新宋體";

?????? font-size:15px;

}

#top

{

?????? width:800px;

?????? height:30px;

?????? border:1px #666666 solid;

?????? border-bottom:1px #333333 dotted;

}

#bottom

{

?????? width:800px;

?????? height:669px;

?????? border-top:0px;

?????? border:1px #666666 solid;

}

#btRed,#btGreen,#btBlue

{

?????? width:30px;

?????? height:15px;

?????? border:1px #999999 solid;

}

#btRed

{

?????? background-color:#FF0000;

}

#btGreen

{

?????? background-color:#00FF00;

}

#btBlue

{

?????? background-color:#0000FF;

}

span

{

????? margin-right:2px;

?????? float:right;

}

</style>

<link id="cssStyle" type="text/css" rel="stylesheet" href=""/>

<script type="text/javascript">

function init()

{

?????? /*當(dāng)?shù)谝淮渭虞d網(wǎng)頁的時候,隨機(jī)產(chǎn)生一個樣式表使用*/

?????? var skinArray=["red","green","blue"];

?????? var index=Math.floor(Math.random()*skinArray.length);

?????? var cssName=skinArray[index];

?????? //document.getElementById("cssStyle").href=cssName+".css";

?????? document.styleSheets[1].href=cssName+".css";

}

function changeSkin(cssName)

{

?????? //document.getElementById("cssStyle").href=cssName+".css";

?????? document.styleSheets[1].href=cssName+".css";

}

</script>

</head>

<body οnlοad="init()">

<div id="main">

?????? <div id="top">

?????? <span>紅色<input type="button" id="btRed"?οnclick="changeSkin('red')"/></span>
   <span>綠色<input type="button" id="btGreen" οnclick="changeSkin('green')"/></span><span>藍(lán)色<input type="button" id="btBlue" οnclick="changeSkin('blue')" />?</span>
   <span>網(wǎng)頁換膚:</span>

?????? </div>

?????? <div id="bottom">

????? </div>

</div>

</body>

</html>

Blue.css

#bottom

{

?????? background-color:#0000FF;

}

Green.css

#bottom

{

?????? background-color:#00FF00;

}

本案例的要點(diǎn)為,同時為頁面準(zhǔn)備多個皮膚(css),當(dāng)首次加載頁面的時候隨機(jī)添加一個皮膚,然后當(dāng)點(diǎn)擊對應(yīng)的皮膚的時候加載對應(yīng)的樣式。同時<link rel="stylesheet" type="text/css"? href=""/>中href=""不可缺少。

轉(zhuǎn)載于:https://www.cnblogs.com/helloczh/articles/1590506.html

總結(jié)

以上是生活随笔為你收集整理的使用js实现换肤功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。