javascript選擇當前頁面所有checkbox 核取方塊代碼
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "HTTP://www.w3.org/tr/xhtml1/dtd/ xhtml1-transitional.dtd">
<html xmlns="HTTP://www.jzread.com/1999/xhtml">
<head>
<meta HTTP-equiv="content-type" content="text/html; charset=gb2312" />
<title>javascript選擇當前頁面所有checkbox 核取方塊代碼</title>
<script language="javascript">
function selectalls(state)
{
var inputs = document.getelementsbytagname("input");
for(var i=0; i< inputs.length; i++)
{
if(inputs[i].type == "checkbox")
{
inputs[i].checked =state;
}
}
}</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<input type="checkbox" name="checkbox" id ="checkbox" />
<label for="checkbox"></label>
<input type="text" name=" textfield" id="textfield" />
<input type="button" name="button" id="button" value="按鈕" onclick=" javascript:selectalls(true);" />
</form>
<label for="textfield"></label>
</body >
</html>