2009-10-27 60 views
0

我怎樣才能得到所有選擇的歌曲,當我點擊playselected按鈕,而不選擇任何歌曲?當我點擊playselected時如何選擇所有歌曲?

</style> 
<script language=JavaScript> 
function checkall() 
{ 
void(d=document); 
void(el=d.getElementsByName('song[]')); 
for(i=0;i<el.length;i++) 
void(el[i].checked=1) 
} 
function uncheckall() 
{ 
void(d2=document); 
void(e2=d2.getElementsByName('song[]')); 
for(i=0;i<el.length;i++) 
void(el[i].checked=0) 
} 

</script> 

<form method="post" action="/player.php" target="player"> 
<table width="747" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
    <td width="150" rowspan="6" valign="top"> 
    </td> 
    <td height="120" colspan="3" align="center" valign="top"></td> 
    <td width="176" rowspan="6" valign="top"></td> 
    </tr> 
    <tr> 
    <!-- movie name --> 
    <td width="179" height="150" align="center" valign="top"><h3><font color="#008080">moviename</font></h3> 

     <!-- movie Description start (add description in between these tags)--> 
<pre> 


</pre>  <!-- movie Description end--> 
     </td> 
    <td colspan="2" valign="top"><img src="/images/moviename.jpg"></td> 
    </tr> 

    <tr> 
    <td width="179" height="44" align="center"><input type=submit value="Play Selected" /></td> 
    <td width="86"><input type=button onClick="checkall()" value="Select All" name="button"></td> 

    <td width="156"><input type=button onClick="uncheckall()" value="Invert Selection" name="button"></td> 
    </tr> 
    <tr> 
    <td colspan="3" valign="top"><table height="342" cellspacing="0" cellpadding="0" border="0" width="423" class="VERDANAFONT"> 
     <tbody> 
     <tr> 
      <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966"> 
<input type="checkbox" name="song[]" value="0_1 ,/telugusongs/moviename/0_1.mp3" /> 
      <!-- song names --> 

      0_1 <br /> 
      </font></p></td> 
      </tr> 
     <tr> 
      <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966"> 
<input type="checkbox" name="song[]" value="0_2 ,/telugusongs/moviename/0_2.mp3" /> 
      <!-- song names --> 
      0_2 <br /> 

      </font></p></td> 
      </tr> 
     <tr> 
      <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966"> 
<input type="checkbox" name="song[]" value="0_3 ,/telugusongs/moviename/0_3.mp3" /> 
      <!-- song names --> 
      0_3 <br /> 
      </font></p></td> 

      </tr> 
     <tr> 
      <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966"> 
<input type="checkbox" name="song[]" value="0_4,/telugusongs/moviename/0_4.mp3" /> 
      <!-- song names --> 
      0_4<br /> 
      </font></p></td> 
      </tr> 

     <tr> 
      <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966"> 
<input type="checkbox" name="song[]" value="0_5 ,/telugusongs/moviename/0_5.mp3" /> 
      <!-- song names --> 
      0_5 <br /> 
      </font></p></td> 
      </tr> 
     <tr> 

      <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966"> 
<input type="checkbox" name="song[]" value="0_6 ,/telugusongs/moviename/0_6.mp3" /> 
      <!-- song names --> 
      0_6<br /> 
      </font></p></td> 
      </tr> 
      <tr> 
      <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966"> 

<input type="checkbox" name="song[]" value="0_7 ,/telugusongs/moviename/0_7.mp3" /> 
      <!-- song names --> 
      0_7 <br /> 
      </font></p></td> 
      </tr> 
      <tr> 
      <td width="423" height="38" align="left" valign="middle"><p> <font color="#339966"> 
<input type="checkbox" name="song[]" value="0_8 ,/telugusongs/moviename/0_8.mp3" /> 
      <!-- song names --> 

      0_8 <br /> 
      </font></p></td> 
      </tr> 
       </tbody> 
    </table></td> 
    </tr> 
</table> 
<table width="800" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
    </tr> 
</table> 

我解釋清楚...當用戶選擇一首歌曲,如果點擊playselect按鈕形式將發佈一首歌曲。這是工作完美。但是,當用戶因此未選擇任何一首歌曲任,如果他點擊playselected按鈕,在這種情況下,我希望所有的歌曲被選中

+1

你想讓你的遊戲選擇按鈕,選擇所有歌曲適合你? – TStamper 2009-10-27 12:01:37

+0

是的,只有當沒有歌曲被選中 – musicking123 2009-10-27 12:08:48

+0

讓我知道它是如何工作的 – TStamper 2009-10-27 19:25:27

回答

0

添加IDplayselect按鈕,這樣的事情應該工作

JavaScript的唯一方法

<input type="Button" id="PlaySelected" value="Play Selected" 
onclick="checklist(myform)"/>//minor changes here made 

function checklist(field) 
{ 
    var answer=false; 
    for (i = 0; i < field.length; i++) 
    { 
    if (field[i].type=="checkbox" && field[i].checked){ 
     answer=true; 
     return false; 
    } 
    } 
    for (i = 0; i < field.length; i++) 
    { 
     field[i].checked = true ; 
    } 
} 

此外,我忘了提及你來「myForm的」添加姓名您form標籤:這裏是一個

Click here for Demo工作版本

jQuery的

$('#PlaySelected').click(function() 
{ 
    var answer=false; 
    $('input[type='checkbox']').each(function(){ 
    answer = this.checked; 
    if(answer==true) 
    { 
     return false; 
    } 
    }); 
    $('input[type='checkbox']').each(function(){ 
     $(this).attr('checked', true); 
    }); 
}); 
+0

對不起請問....可以ü請告訴我在哪裏我必須添加代碼$ 在我的代碼 – musicking123 2009-10-27 13:57:30

+0

?即時通訊不知道你問的問你在哪裏添加jQuery代碼? – TStamper 2009-10-27 14:07:14

+0

參考http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery獲取更多詳細信息和示例 – TStamper 2009-10-27 14:12:23

相關問題