HTML学习(一)

来源:互联网 发布:淘宝引流是什么意思 编辑:程序博客网 时间:2024/05/22 15:16

HTML学习(一)

HTML 标签

 

一.用bgsound和js实现音乐的点击播放和取消的简易版

1.  设置初始的bgsound为

<bgsound id="mp3" loop="-1"src="">

2.  用js写一个简易的函数改变bgsound,传入的为音乐地址

  <scripttype="text/javascript">

       functionplay(s){

                   varss=document.getElementById('mp3').src;

                   //window.confirm(ss);

                   if(ss==s){

                            document.getElementById('mp3').setAttribute('src',"");

                   }

                   else{

                            document.getElementById('mp3').setAttribute('src',s);

                   }

         }

  </script>

3.  写一个鼠标单击事件onclick,传入音乐地址
onclick="play('1.mp3')"

4.  之后就只要自身需要组合就行

PS:由于bgsound的局限性(仅IE提供),所以此方法简单,却仅支持IE


示例:

<!DOCTYPE html>

<html >

<head>

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

</head>

 

<body>

<input type="button"value="播放1" onclick="play('1.mp3')">

<input type="button"value="播放2" onclick="play('2.mp3')">

<input type="button"value="播放3" onclick="play('3.mp3')">

<bgsound id="mp3" loop="-1"src="">

 

 <script type="text/javascript">

       function play(s){

                   varss=document.getElementById('mp3').src;

                   window.confirm(ss);

                   if(ss==s){

                            document.getElementById('mp3').setAttribute('src',"");

                   }

                   else{

                            document.getElementById('mp3').setAttribute('src',s);

                   }

         }

 </script>

</body>

</html>


0 0