1.html文件
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>音乐播放试听列表</title> </head> <body> <script src="https://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <div> <div> <div> <ol> <audio src="">你的浏览器不支持音频播放</audio> <li> <label>MusicNAME1</label> <a href="#"> <img src="https://sandbox.runjs.cn/uploads/rs/424/shsayjwv/play.png"> </a> </li> <li> <label>MusicNAME2</label> <a href="#"> <img src="https://sandbox.runjs.cn/uploads/rs/424/shsayjwv/play.png"> </a> </li> <li> <label>MusicNAME3</label> <a href="#"> <img src="https://sandbox.runjs.cn/uploads/rs/424/shsayjwv/play.png"> </a> </li> <li> <label>MusicNAME4</label> <a href="#"> <img src="https://sandbox.runjs.cn/uploads/rs/424/shsayjwv/play.png"> </a> </li> <li> <label>MusicNAME5</label> <a href="#"> <img src="https://sandbox.runjs.cn/uploads/rs/424/shsayjwv/play.png"> </a> </li> </ol> <script type="text/javascript" src="https://www.jb51.net/play.js"></script><!-- 播放/暂停 --> </div> </div> </div> </body> </html>
2.run.js
// // @author FUCMLIF // @date 2016/4/6 // jQuery("a.user_doplay").click(function(){ var x = document.getElementById("myAudio"); if (x.paused) { jQuery("a.user_doplay").find('img').attr('src','https://sandbox.runjs.cn/uploads/rs/424/shsayjwv/play.png'); jQuery(this).find('img').attr('src','http://sandbox.runjs.cn/uploads/rs/424/shsayjwv/stop.png'); jQuery(this).attr("name","playing"); x.play(); //播放 } else if (x.play && jQuery(this).attr("name") == "stoped") { jQuery('#myAudio').attr('src',jQuery(this).attr('id') + '.mp3');//修改音频路径 jQuery("a.user_doplay").find('img').attr('src','https://sandbox.runjs.cn/uploads/rs/424/shsayjwv/play.png'); jQuery(this).find('img').attr('src','http://sandbox.runjs.cn/uploads/rs/424/shsayjwv/stop.png'); jQuery("#play_list_ol").find('a').attr('name','stoped'); jQuery(this).attr("name","playing"); x.play(); //播放 } else if (x.play && jQuery(this).attr("name") == "playing") { jQuery(this).find('img').attr('src','https://sandbox.runjs.cn/uploads/rs/424/shsayjwv/play.png'); jQuery("#play_list_ol").find('a').attr('name','stoped'); x.pause(); //暂停 } else { alert("这个提示不应该出现"); } });