日期:2014-05-17 浏览次数:20625 次
<html> <head> <title>音乐网站那种全选反选连续播放</title> <script language="javascript"> function MusicClass(form,chkboxName,btn1,btn2,btn3,btn4) { var obj = { SelectAll:btn1, ClearAll:btn2, SelectOther:btn3, PlayMusic:btn4 }; var box = document.getElementsByName(chkboxName); Function.prototype.ChkMusic = function () { var me = this; return function () { for (var i=0;i<box.length;i++) { me(i); } } } obj.SelectAll.onclick = function(i){ box[i].checked = true; }.ChkMusic(); obj.ClearAll.onclick = function(i){ box[i].checked = false; }.ChkMusic(); obj.SelectOther.onclick = function(i){ box[i].checked = !box[i].checked }.ChkMusic(); obj.PlayMusic.onclick = function () { for (var i=0;i<box.length;i++) { if (box[i].checked) { //form.submit(); return; } } alert("对不起,请至少选择一首歌曲再播放!"); } } window.onload = function () { MusicClass(document.forms[0],'MusicID',document.all.All,document.all.Clear,document.all.Other,document.all.Play); } </script> </head> <body> <form action=" method="get"> <input type='checkbox' name='MusicID' value="1" />东风破<br /> <input type='checkbox' name='MusicID' value="2" />Super Star <br /> <input type='checkbox' name='MusicID' value="3" />算你狠 <br /> <input type='checkbox' name='MusicID' value="4" />十年 <br /> <input type='checkbox' name='MusicID' value="5" />痴心绝对 (爱上痞子男 <br /> <button id="All">全选</button> <button id="Clear">全不选</button> <button id="Other">反选</button> </form> </body> </html>