国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

JS實現的圖片選擇順序切換和循環切換功能示例【測試可用】

2024-05-06 15:43:48
字體:
來源:轉載
供稿:網友

本文實例講述了JS實現的圖片選擇順序切換和循環切換功能。分享給大家供大家參考,具體如下:

<!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>圖片切換</title><style type="text/css">#box{width:400px;margin:0 auto;}#box>div{text-align: center;margin:10px auto;display: block;}#box div>input{margin-left: 5px;border-radius: 3px;border:1px solid #ccc;}#box>p{text-align: center;}#content{width:400px;height:400px;margin:0 auto;position: relative;border:10px solid #ccc;}#content a{width:40px;height:40px;background:#000;border:5px solid #fff;position: absolute;top:175px;text-align: center;text-decoration: none;line-height: 40px;color:#ccc;font-weight: 900;filter: alpha(opacity:40);opacity: 0.4;}#content a:hover{filter: alpha(opacity:90);opacity: 0.9;}#prev{left:10px;}#next{right:10px;}#text,#span{position: absolute;bottom: 0;left:0;width:400px;height:30px;background:#000;line-height: 30px;text-align: center;color: #fff;filter: alpha(opacity:80);opacity: 0.8;}#text{margin:0;bottom: 0;}#span{top:0;}#img{width:400px;height:400px;}</style><script type="text/javascript">   window.onload=function(){   var oPrev=document.getElementById('prev');   var oNext=document.getElementById('next');   var oText=document.getElementById('text');   var oSpan=document.getElementById('span');   var oImg=document.getElementById('img');   var oBtn1=document.getElementById('btn1');   var oBtn2=document.getElementById('btn2');   var oP1=document.getElementById('p1');   var arrUrl=['images/1.jpg','images/2.jpg','images/3.jpg','images/4.jpg'];   var arrText=['baby','冰冰','唐嫣','楊冪'];   var num=0;   //初始化   function fnTab(){   oSpan.innerHTML=num+1+'/'+ arrText.length;   oText.innerHTML=arrText[num];   oImg.src=arrUrl[num];      };      fnTab();   oBtn1.onclick=function(){    oNext.onclick=function(){    num++;    if(num==arrText.length){     num=0;    }     fnTab();   };    oPrev.onclick=function(){    num--;    if(num==-1){     num=arrText.length-1;    }     fnTab();   };    /*oPrev.onclick=function(){     if(0<num){      num--;      fnTab();     }else{      num=arrText.length;      num--;     }    };*/   };    oBtn2.onclick=function(){    oP1.innerHTML = '圖片只能到最后一張或第一張切換';    oNext.onclick=function(){    if(num==arrText.length-1){     alert('這是最后一張了。。');    }else{     num++;    }    /*if(num==arrText.length){     alert('這是最后一張了。。');    }*/     fnTab();   };    oPrev.onclick=function(){    if(num==0){    alert('這已經是第一張了,不能再切換了。。');    }else{     num--;    }     fnTab();   };   };   /* oNext.onclick=function(){    num++;    if(num==arrText.length){    num=0;    }    fnTab();   };   oPrev.onclick=function(){    num--;    if(num==-1){    num=arrText.length-1;    }    fnTab();   };*/   };</script></head><body>  <div id="box">   <div>    <input id="btn1" type="button" value="循環切換">    <input id="btn2" type="button" value="順序切換">   </div>   <p id="p1">圖片可以從最后一張跳到第一張循環切換</p>  </div>  <div id="content">    <a href="javascript:;" rel="external nofollow" rel="external nofollow" id="prev"><</a>    <a href="javascript:;" rel="external nofollow" rel="external nofollow" id="next">></a>    <p id="text">圖片文字加載中......</p>    <span id="span">數量正在計算中......</span>    <img id="img" />  </div></body></html>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 金阳县| 桑日县| 田东县| 雷山县| 五指山市| 湛江市| 辉县市| 浦县| 芒康县| 宝清县| 固阳县| 旌德县| 阿鲁科尔沁旗| 墨竹工卡县| 景泰县| 田林县| 金阳县| 枞阳县| 怀来县| 榆树市| 封丘县| 施秉县| 禹州市| 云林县| 沙洋县| 静乐县| 来宾市| 兴国县| 屏山县| 呼图壁县| 阿拉善左旗| 荔浦县| 邵阳市| 上蔡县| 辉南县| 体育| 仪征市| 丹棱县| 左云县| 昌乐县| 襄樊市|