批量添加歌曲的JS脚本
完整的代码如下:
[html]<code>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>批量添加歌曲</title>
<style type="text/css">
<!--
.style1 {
color: #006666;
font-weight: bold;
}
.blank{FONT-FAMILY:宋体;FONT-SIZE:9pt}
a{font-family:"宋体","Verdana","Arial";font-size:9pt;text-decoration:none;color:#330099;line-height:14pt}
A:link{COLOR:#004080;FONT-SIZE:9pt;TEXT-DECORATION:none}
A:visited{TEXT-DECORATION:none}
A:hover{COLOR:red;TEXT-DECORATION:underline}
body,table,p,td,font,input,select,textarea,font{
font-size:9pt;font-family:宋体,Times New Roman,Times,serif;LINE-HEIGHT:130%;;scrollbar-face-color:145f74;scrollbar-3dlight-color:ffffff;scrollbar-darkshadow-color:ffffff;scrollbar-track-color:FFFFFF;scrollbar-arrow-color:ffffff;scrollbar-shadow-color:ffffff}
textarea,select{letter-spacing:1px;background-color:#f3f5f5;}
input{font-size:9pt;background-color:lightgray;color:blank}
-->
</style>
<SCRIPT language="javascript">
<!--
function CheckForm()
{
var f = event.srcElement;
if (f.classid.value=='' || f.Nclassid.value=='')
{
alert("错误: 请先选择分类!");
return false;
}
var oSongName = document.getElementsByName("SongName");
var oListenUrl = document.getElementsByName("ListenUrl");
for(var i=0;i< oSongName.length;i++)
{
if (oSongName[i].value == '' || oListenUrl[i].value == '')
{
alert("错误: 歌曲名或试听地址为空! [歌曲"+i+"]");
return false;
}
}
return true;
}
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript" defer>
<!--
var i=0;
var t,tr;
t = document.getElementsByTagName("table")[0];
tr = document.getElementById("tfs");
//添加新行
function addNewRow(){
var tid= ++i;
createNewRow(tid);
}
//创建新节点
function createNewRow(rIdx){
var newTr = tr.cloneNode(true);
var tmpStr = newTr.innerHTML.replace("歌曲0",'歌曲'+rIdx);
tmpStr = tmpStr.replace(/hot\d/ig,"hot"+rIdx);
newTr.innerHTML = tmpStr;
t.insertRow().appendChild(newTr);
}
//重新排序
function reSort(){
var e=event.srcElement;
var tCount = t.rows.length;
if(e.checked){
for(var i=3;i<tCount;i++){
t.rows[3].removeNode(true);
createNewRow(i-2);
}
}
}
//删除行
function deleteRow(){
var tCount = t.rows.length;
if(tCount>3){
var e = event.srcElement;
var currTr = e.parentElement.parentElement.parentElement.parentElement;
var currId = currTr.rowIndex;
var oCheck = document.getElementById("autoSort");
if(currId!=tCount && oCheck.checked)
{
for(var n=currId ;n<tCount;n++)
{
var tmpObj = t.rows[currId];
tmpObj.removeNode(true);
(n!=currId)?createNewRow(n-3):'';
}
}
else
{
currTr.removeNode(true);
}
(oCheck.checked)?i=t.rows.length-3:'';
}
else
{
alert("请至少保留一栏!");
}
}
//-->
</SCRIPT>
</head>
<body bgcolor=#468ea3 topmargin="0"><BR>
<span id="output" ></span>
<form method="POST" name="myform" action="" onsubmit="return CheckForm()">
<TABLE width="650" border="0" align="center" cellspacing="1">
<TR align="center">
<TD colspan="5" height="25" bgcolor="#145f74"><b><FONT color="#FFFFFF">批 量 添 加 歌 曲</FONT></b></TD>
</TR>
<TR>
<TD width="69" height="30" align="right" nowrap bgcolor="#A5D0DC"><B><font color="#FF0000"> DJ 类型</font>:</B></TD>
<TD width="109" height="30" bgcolor="#A5D0DC">
<SELECT name="classid" size="1">
<OPTION value="">=请选择栏目=</OPTION>
<OPTION value="1">分类1</OPTION>
<OPTION value="2">分类2</OPTION>
</SELECT>
</TD>
<TD width="81" height="30" align="right" bgcolor="#A5D0DC"><B>选择分类:</B></TD>
<TD width="113" height="30" bgcolor="#A5D0DC">
<SELECT name="Nclassid">
<OPTION selected value="1">==请选分类==</OPTION>
</SELECT>
</TD>
<TD width="266" bgcolor="#A5D0DC"><span class="style1" style="cursor:hand" onclick="addNewRow()">添加输入栏 </span>
<span class="style1" style="cursor:hand">
<input name="autoSort" type="checkbox" id="autoSort" value="checkbox" checked onclick="reSort()"><label for="autoSort">自动重排</label></span>
</TD>
</TR>
<TR>
<TD height="30" colspan="5" align="right" nowrap bgcolor="#A5D0DC" id="tfs">
<fieldset style="width:650px;">
<legend>歌曲0 <a style="cursor:hand" onclick="deleteRow()" class="style1">[删除此栏]</a></legend>
<TABLE width="650" border="0" align="center" cellspacing="1">
<td width="76" align="right" height="30" nowrap bgcolor="#cce6ed"><b><font color="#FF0000"> 歌曲名</font>:</b></td>
<td width="450" height="30" colspan="3" bgcolor="#cce6ed">
<input name="SongName" type="text" class="smallinput" size="82" maxlength="100">
</td>
</tr>
<tr>
<td width="76" align="right" height="30" nowrap bgcolor="#cce6ed"><b><font color="#FF0000"> 试听地址</font>:</b></td>
<td width="450" height="30" colspan="3" bgcolor="#cce6ed">
<input name="ListenUrl" type="text" class="smallinput" size="82" maxlength="100">
</td>
</tr>
<tr bgcolor="#cce6ed">
<td width="76" align="right" height="30" nowrap bgcolor="#cce6ed"><b>推荐度:</b></td>
<td width="450" height="30" colspan="3" bgcolor="#cce6ed">
<input type="radio" value="1" name="hot0">1星.
<input type="radio" value="2" name="hot0">2星.
<input type="radio" value="3" name="hot0">3星.
<input type="radio" value="4" name="hot0">4星.
<input type="radio" value="5" name="hot0" checked>5星.
<!--<input type="text" name="hot" size="60" class="smallinput" maxlength="100" value="3">-->
</td>
</tr>
</TABLE>
</fieldset>
</TD>
</TR>
</TABLE>
<p> </p>
<div align="center"><center><p><input type="submit" value=" 添 加 "
name="cmdok" class="buttonface"> <input type="reset" value=" 清 除 "
name="cmdcancel" class="buttonface"></p>
</center></div>
</form>
</body>
</html>[/code]