要完成此效果需要兩個(gè)步驟
第一步:把如下代碼加入到區(qū)域中
<script LANGUAGE="JavaScript">
counter = 0;
html = true;
mp3list = "#EXTM3U";
if(html) {
mp3list += "
";
}
mp3list += "\n";
file = "";
songs = new Array();
function addsong() {
file = document.forms[0].file.value;
file = file.toLowerCase();
if(file == "") {
alert("按“瀏覽”選擇一個(gè)文件");
}
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("請(qǐng)加入曲目到列表中!");
}
else {
mp3l = songs.length;
for(i = 0; i < mp3l; i++) {
if(songs[i] != "") {
mp3list += songs[i];
if(html) {
mp3list += "
"
}
mp3list += "\n"
}
}
document.write(mp3list);
if(html) {
document.write("
");
document.write("alert('創(chuàng)建一外空白文件,拷貝以下代碼到文件中并保存為.m3u后綴的文件\\n\\n按瀏覽器返回按鈕,回到編輯頁(yè)面')");
document.write("");
}
}
document.forms[0].sofar.blur();
}
function deletethis() {
if(counter > 0) {
counter--;
document.forms[0].sofar[counter] = null;
songs[counter] = "";
}
else {
alert("列表中無(wú)項(xiàng)目!");
}
}
</script>
第二步:把如下代碼加入到區(qū)域中
選擇MP3文件后按添加按鈕,全部選擇完畢后按“結(jié)束”。