一,簡(jiǎn)單版
創(chuàng)新互聯(lián)建站自2013年起,先為易門等服務(wù)建站,易門等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為易門企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。<body> <header> <img src="img/2.jpg" alt="" > <select id="btn"> <option value="">請(qǐng)選擇</option> <option>背景春</option> <option>背景夏</option> <option>背景秋</option> <option>背景冬</option> </select> <select id="btn1"> </select> <h2><i>-春之情-主頁導(dǎo)航</i></h2> <span><a href="#">換膚學(xué)習(xí)</a></span> <img src="img/2.jpg" alt="" > <img src="img/loading.gif" alt="" > </header> <div id="content"> <img src="img/bg1.jpg" alt="圖片" > </div> <script src=script/jquery-1.11.3.js></script> <script> //原生js實(shí)現(xiàn) function changeskin(imgurl){ var imgobj=document.getElementsByTagName('img') ; imgobj[3].src=imgurl; } window.onload=function(){ var btnobj=document.getElementById("btn"); var btnobj1=document.getElementById("btn1"); btnobj.addEventListener("change",function(){ var index=btnobj.selectedIndex; var imgurl=[" ","img/bg3.jpg","img/bg2.jpg","img/bg4.jpg","img/bg5.jpg"]; //使用DOM方式新增選項(xiàng) var newoption=document.createElement("option"); newoption.appendChild(document.createTextNode("新增選項(xiàng)")); btnobj.appendChild(newoption); var text=btnobj.options[index].text;//獲得select選項(xiàng)中的文本值 //使用selected屬性設(shè)置為true,來選擇選項(xiàng) if(btnobj.options[index].selected){ changeskin(imgurl[index]);} //使用remove方法移除 btnobj.remove(2); } </script> </body>
實(shí)現(xiàn)效果圖:
初始頁面:
選擇選項(xiàng)中的,背景冬:
背景換為:
總結(jié):這是學(xué)習(xí)幾個(gè)簡(jiǎn)單方法,做的簡(jiǎn)單小例子,在后期,還會(huì)繼續(xù)完善,目標(biāo):
(1)使用jquery實(shí)現(xiàn)這個(gè)效果
(2)結(jié)合cookie實(shí)現(xiàn)頁面定制效果。
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動(dòng)態(tài)BGP最優(yōu)骨干路由自動(dòng)選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機(jī)房獨(dú)有T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進(jìn)行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動(dòng)現(xiàn)已開啟,新人活動(dòng)云服務(wù)器買多久送多久。
當(dāng)前標(biāo)題:select學(xué)習(xí)小demo--實(shí)現(xiàn)網(wǎng)頁換膚-創(chuàng)新互聯(lián)
新聞來源:http://muchs.cn/article16/cdiedg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、虛擬主機(jī)、網(wǎng)頁設(shè)計(jì)公司、網(wǎng)站營銷、定制網(wǎng)站、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容