JavaScript数组

来源:互联网 发布:杜比音效增强软件 编辑:程序博客网 时间:2024/06/14 18:01

index1.html

<html><head><meta name="lucheng" content="text/html;charset=UTF-8"><title>数组遍历</title></head><body><script>function fun1() {arr=["HTML","CSS","JavaScript"]document.write(arr[0] + "<br/>");document.write(arr[1] + "<br/>");document.write(arr[2] + "<br/>");}function fun2(){arr=["HTML","CSS","JavaScript"]var n = 0;while(n < arr.length) {document.write(arr[n]+"<br/>");n++;}}function fun3(){arr=["HTML","CSS","JavaScript"]for(var n=0;n < arr.length;n++) {document.write(arr[n]+"<br/>")}}</script><button onclick="fun1()">点击这里</button><button onclick="fun2()">点击这里</button><button onclick="fun3()">点击这里</button></body></html>

index2.html

<!DOCTYPE html> <html> <body> <div style="text-align:center;">  <video id="video" width="720" style="margin-top:15px;"><source id="source" src="" type="video/mp4" />Your browser does not support HTML5 video.  </video>  <br/>  <button onclick="playPause()">播放/暂停</button>   <button onclick="makeBig()">大</button>  <button onclick="makeNormal()">中</button>  <button onclick="makeSmall()">小</button>  <button onclick="previous()">播放上一集</button>  <button onclick="next()">播放下一集</button></div> <script type="text/javascript">arr=["龙卷风.mp4","给我一首歌的时间.mp4","喜欢你.mp4"];document.getElementById("source").src=arr[0];var n = 0;/*播放下一集*/function next() {if(n<(arr.length-1)){n=n+1;document.getElementById("source").src=arr[n];myVideo.load();myVideo.play(); }}/*播放上一级*/function previous() {if(n>0) {n=n-1;document.getElementById("source").src=arr[n];myVideo.load();myVideo.play(); }}/*单播放按钮点击时,播放视频或暂停视频*/function playPause() { if (myVideo.paused) myVideo.play(); else myVideo.pause(); } /*视频显示宽度调宽*/function makeBig() { myVideo.width=560; } /*视频显示宽度调成适中*/function makeNormal() { myVideo.width=420; } /*视频显示宽度调窄*/function makeSmall() { myVideo.width=320; } /*获取要播放的视频*/var myVideo=document.getElementById("video");/*页面加载完后,自动掉用playPause(),开始播放*/window.onload = playPause();</script> </body> </html>


原创粉丝点击