0

我正在尝试从列表中运行视频我有我使用两个按钮从列表中运行下一个以前的视频,默认情况下它运行第一个但它给我错误而且我也很困惑所以我需要帮助让它运行让我告诉它是我的视频列表代码,

    <div>
<SELECT id=cancion onchange=PlayIt() size=20 name="cancion" style="width: 470; color:#C0C0C0; height:22; background-color:#000000;">
<option value=Peace1.wmv>. . Countdown</option>
<option value=Fire.wmv>. . Time Crisis 4</option>
<option value=Water.wmv>. . Need For Speed</option>
<option value=http://liamalexander.com/computing/gallery/albums/video/assessment.wmv>. . Meli's Video</option>
<option value=http://liamalexander.com/computing/gallery/albums/video/k_0001.wmv>. . Keldin's Video</option>
<option value=http://liamalexander.com/computing/gallery/albums/video/Skateboard_Tricks_Video.wmv>. . Chris's Video</option>
<option value=http://liamalexander.com/computing/gallery/albums/video/video_0001.wmv>. . Salinina's Video</option>
<option value=http://liamalexander.com/computing/gallery/albums/video/JORDAN_MOVES_23.wmv>. . Josh's Video</option>
<option value=http://liamalexander.com/computing/gallery/albums/video/robots_video_0001.wmv>. . Sam's Video</option>
<option value=http://liamalexander.com/computing/gallery/albums/video/Unexpected2.wmv>. . Unexpected</option>
<option value=http://liamalexander.com/computing/gallery/albums/video/By_brendan_wu.wmv>. . Brendan's Video</option>
<option value=http://liamalexander.com/computing/gallery/albums/video/rebecca01.wmv>. . Rebecca's Video 1</option>
<option value=http://liamalexander.com/computing/gallery/albums/video/rebecca_robots002.wmv>. . Rebecca's Video 2</option>
<option value=http://liamalexander.com/computing/gallery/albums/video/robotics_videoo_002.wmv>. . Robotics Video</option>
<option value=http://liamalexander.com/computing/gallery/albums/video/joys_01.wmv>. . The Joys of Spring</option>
</SELECT>
</div>

我们有两个按钮 next 和 previous 用于切换视频,

<button type="button" onclick="showDiv(1 - 1)">Previous</button>
<button type="button" onclick="showDiv(1 + 1)">Next</button>

现在将在下一个或上一个按钮上运行的脚本,

function showDiv(which) {
var currentImage = 1;
   for(i = 0; i < 13; i++) {
      //document.getElementById("image"+i).style.display="none";
 document.getElementById("music1").innerHTML='<object id="mediaPlayer" width="470" height="400" '
+'classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" '
+'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" '
+'standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">'
+'<param name="fileName" value="'+document.getElementById('cancion'+i).value+'">'
+'<param name="animationatStart" value="true">'
+'<param name="transparentatStart" value="true">'
+'<param name="autoStart" value="1">'
+'<param name="showControls" value="true">'
+'<param name="loop" value="true">'
+'<param name="ShowStatusBar" value="true">'
+'<param name="ShowPositionControls" value="true">'
+'<param name="enableContextMenu" value="1" />'
+'<param name="fullScreen" value="0" />'
+'<embed type="application/x-mplayer2" '
+'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" '
+'bgcolor="darkblue" showcontrols="true" showpositioncontrols="true" showstatusbar="true" showgotobar="true" width="470" height="400" '
+'src="'+document.getElementById('cancion'+i).value+'" autostart="true" designtimesp="5311" loop="true">'
+'</embed>'
+'</object>'
   }
   //in the next 2 lines, you make sure which isn't lower than 1, and isn't greater than the number of images
   if(which < 1) which = 1;
   if(which > 13) which = 13;
   document.getElementById("image" + which).style.display = "block";
   currentImage = which;
} 

我正在使用三个视频“Peace1”“火”“水”你可以在这里使用任何视频你必须检查这个代码

希望尽快收到您的来信,提前谢谢

4

1 回答 1

1

这是您应该使用的脚本:

<script type="text/javascript">

       var currentTrack = 1;

       function showDiv(direction) {

             if(direction == "prev") {
                 // previous pressed
                 if(currentTrack > 1) {
                     currentTrack--;
                 }
             } else {
                 // next pressed
                 if(currentTrack < 13) {
                     currentTrack++;
                 }
             }

             document.getElementById("image" + currentTrack).style.display = "block";

             document.getElementById("music1").innerHTML='<object id="mediaPlayer" width="470" height="400" '
                    +'classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" '
                    +'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" '
                    +'standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">'
                    +'<param name="fileName" value="'+document.getElementById('cancion').options[currentTrack].value+'">'
                    +'<param name="animationatStart" value="true">'
                    +'<param name="transparentatStart" value="true">'
                    +'<param name="autoStart" value="1">'
                    +'<param name="showControls" value="true">'
                    +'<param name="loop" value="true">'
                    +'<param name="ShowStatusBar" value="true">'
                    +'<param name="ShowPositionControls" value="true">'
                    +'<param name="enableContextMenu" value="1" />'
                    +'<param name="fullScreen" value="0" />'
                    +'<embed type="application/x-mplayer2" '
                    +'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" '
                    +'bgcolor="darkblue" showcontrols="true" showpositioncontrols="true" showstatusbar="true" showgotobar="true" width="470" height="400" '
                    +'src="'+document.getElementById('cancion').options[currentTrack].value+'" autostart="true" designtimesp="5311" loop="true">'
                    +'</embed>'
                    +'</object>'
       }


</script>

按钮也相应改变:

<button type="button" onclick="showDiv('prev')">Previous</button>
<button type="button" onclick="showDiv('next')">Next</button>

我想告诉你几件事:
1. 对于属性使用“”或“”
2. 不要执行 onclick="",通过 javascript 绑定事件处理程序(我将示例保持不变,以便您可以学习一些搜索有关如何绑定事件处理程序的答案)

祝你好运!

于 2012-06-11T09:26:24.290 回答