JQuery中全選與反選的

JSP頁面table的HTML代碼:
<table style="color:#000;border-collapse: collapse;width: 100%;border-color: red;" border="1"  >
	<tr><th>序號</th><th>附件名</th><th>是否發送[全選<input type="checkbox" name="allCheck" value="111" onclick="doSelectAll(this);" /> ]</th></tr>
<span style="white-space:pre">		</span>
<span style="white-space:pre">	</span><%	for(Iterator iterator = attachColl.iterator(); iterator.hasNext();){ attachIndex++;EntityMap attMap = (EntityMap) iterator.next();%>
			
<span style="white-space:pre">	</span><tr><td><%=attachIndex %></td><td align="left"><%=attMap.getJspString("fsfilename")%></td>
<span style="white-space:pre">		</span><td><input type="checkbox" name="atach" value="<%=attMap.getJspString("fsid")%>"  /> </td> </tr>
		<%} %>
							</table>



JQuery代碼:

	function doSelectAll(obj){
		if($("input[name=allCheck]").get(0).checked){//點擊全選
			$("input[name=atach]").each(function(){
	 			$(this).attr('checked', true);
	 		});
		}else{//取消全選
			$("input[name=atach]").each(function(){
	 			$(this).attr('checked', false);
	 		});
		}
 	} 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章