Posted on 2011-11-27 21:54
哈希 閱讀(167)
評論(0) 編輯 收藏 所屬分類:
Js and Jquery 常用總結
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<script language="javascript">
function searchFriend(){
//得到所有的復選框
var s=document.getElementById("allFriend");
var ack=document.getElementsByName("chkFriend");
for(var i=0;i<ack.length;i++){
if(ack[i].type=="checkbox"){
ack[i].checked=s.checked;
}
}
}
function rsearchFriend(){
var ack=document.getElementsByName("chkFriend");
for(var i=0;i<ack.length;i++){
if(ack[i].type=="checkbox"){
ack[i].checked=!ack[i].checked;
}
}
}
</script>
</head>
<body>
<form name="chkFriend" method="post" action="">
<p>你想交一個什么樣的朋友呢,請選擇:</p>
<p>
<!-- 所有的復選框名字需要調整一致 -->
<input type="checkbox" name="chkFriend" value="溫柔"> 溫柔
<input type="checkbox" name="chkFriend" value="年輕"> 年輕
<input type="checkbox" name="chkFriend" value="漂亮"> 漂亮
<input type="checkbox" name="chkFriend" value="愛洗衣服">愛洗衣服
<input type="checkbox" name="chkFriend" value="愛做飯">愛做飯
</p>
<p>
<input type="checkbox" onClick="searchFriend()" id="allFriend" name="allFriend" value="以上全選">以上全選
</p>
<input type="checkbox" onClick="rsearchFriend()" id="rallFriend" name="rallFriend" value="反選">反選
</p>
<p>
<input type="button" name="Submit" value="尋找目標">
</p>
</form>
</body>
</html>