首页 >> 网页特效 >> 代码生成 >> 正文
来源: 本站原创 | 时间: 2006-1-13 18:49:27 | 人气:
MP3播放列表文件生成器
要完成此效果需要两个步骤
第一步:把如下代码加入到<head>区域中
<SCRIPT LANGUAGE="JavaScript">counter = 0;html = true;mp3list = "#EXTM3U";if(html) {mp3list += "<br>";}mp3list += "\n";file = "";songs = new Array();function addsong() {file = document.forms[0].file.value;file = file.toLowerCase();if(file == "") {alert("按“浏览”选择一个文件");}else {fn = file;char = unescape("%5C");while(fn.indexOf(char) != -1) {pos = fn.indexOf(char);fn = fn.substring(pos + 1, fn.length);}if(fn.indexOf('.mp3') == -1) {alert("只能是MP3格式文件!");}else {songs[counter] = file;document.forms[0].sofar[counter] = new Option((counter+1) + ": " + fn, file, false, true);counter++;}document.forms[0].file.value = ""; }}function finish() {if(counter == 0) {alert("请加入曲目到列表中!");}else {mp3l = songs.length;for(i = 0; i < mp3l; i++) {if(songs[i] != "") {mp3list += songs[i];if(html) {mp3list += "<br>"}mp3list += "\n" }}document.write(mp3list);if(html) {document.write("<scr"+"ipt>");document.write("alert('创建一外空白文件,拷贝以下代码到文件中并保存为.m3u后缀的文件\\n\\n按浏览器返回按钮,回到编辑页面')");document.write("</scr"+"ipt>"); }}document.forms[0].sofar.blur();}function deletethis() {if(counter > 0) {counter--;document.forms[0].sofar[counter] = null;songs[counter] = "";}else {alert("列表中无项目!"); }}</script>
第二步:把如下代码加入到<body>区域中
<div align="center">选择MP3文件后按添加按钮,全部选择完毕后按“结束”。 </div><form> <div align="center"> <input type=file name=file value=""> <input type=button value="添加" onClick="addsong()"> <br> <br> <br> <select name=sofar style="width:350;" size=20 multiple> </select> <br> <br> <input type=button value="结束" onClick="finish();"> <input type=button onClick="deletethis()" value="删除最后一条曲目"> </div></form>