JavaScript实现全选和反选 超简单
<body>
<form id="form1" runat="server">
请选择你的爱好:
<div>
<input name="Che" type="checkbox" />足球
<input name="Che" type="checkbox" />篮球
<input name="Che" type="checkbox" />上网
<input name="Che" type="checkbox" />游戏
<input name="Che" type="checkbox" />逛街
<input name="Che" type="checkbox" />购物
<input name="Che" type="checkbox" />排球
<input name="Che" type="checkbox" />看书
</div>
<input id="btnquan" type="button" onclick="quan()" value="全选" />
<input id="btnfan" type="button" onclick="fan()" value="反选" />
</form>
</body>
<script>
//全选的方法 超简单
function quanxuan()
{
//获得 所有的复选框
var che=document.getElementByName("Che");
//循环所有的复选框
for(var i=0;i<che.length;i++)
{
che[i].checked=true;
}
}
//反选的方法
function fanxuan()
{
//同样也是获得所有的复选框
var che=document.getElementByName("Che");
//同样for循环
for(var i=0;i<che.length;i++)
{
if(che[i].checked==true)
{
che[i].checked=false;
}
else
{
che[i].checked=true;
}
}
}
</script>
相关文档:
发现自己代码中用if的地方比较多,于是就在上周对case语句好好研究了一番并优化了自己的部分代码。因此出现了如下if和case的比较一说。声明当case的条件块中没用break时候,是和if一样的一个一个的条件来判断执行。当条件中有了break,编译器会为它做二分法优化(或跳转表),就是根据条件来跳转,平均性能高于if。
定义: d ......
打开一个 js 文件,编辑完成保存时,突然提醒下面的错误:
Save could not be completed.
Reason:
Some characters cannot be mapped using “ISO-8859-1″ character encoding. Either change the encoding or remove the characters which are not supported by the “ISO-8859-1″ character ......
function GetUrlParms(){
var args=new Object();
var query=location.search.substring(1);//获取查询串
var pairs=query.split("&");//在逗号处断开
for(var i=0;i<pairs.length;i++){
var pos=pairs[i].indexOf('=');//查找name=value
if(pos==-1) c ......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>随机 ......
1.日期对象的构造
1.1当前日期
var now = new Date();
1.2特定日期
var someDate = new Date(yyyy,mm,dd);
注:月应该是从0开始计数的.
2. 日期函数的使用可以参照下面的链接. http://www.w3schoo ......