JS遍历所有checkbox是否选中

1
2
3
4
5
6
7
var all_checked = true;  
$(":checkbox").each(function(){
if(this.checked == false){
all_checked = false;
break;
}
});

注意:用break,想跳出这个循环。结果报错
SyntaxError: unlabeled break must be inside loop or switch
经查,在回调函数里return false即可,大多数jquery的方法都是如此的。

返回 ‘false’ 将停止循环 (就像在普通的循环中使用 ‘break’)。
返回 ‘true’ 跳至下一个循环(就像在普通的循环中使用’continue’)。

让页面在打开时自动刷新

1
2
3
4
5
6
7
<script>
function window.onload() {
if (location.href.indexOf('#reloaded') == -1) {
location.href = location.href + "#reloaded"location.reload()
}
}
</script>

-————————————————————–

我的网页的图片较多,而服务器也不是很好,所以每次打开网页后总有一、两幅图片无法显示,但刷新一遍后又全部可显示了。
不想让浏览网页的人每次都点“刷新”按钮,请问如何在网页中加入一些代码,让网页在打开后又自动刷新一次?
-————————————————————–

把下面代码加在<head></head>之间
<meta http-equiv=refresh content=5 > //每隔5秒刷新一次
-————————————————————–

Read More

Linux apache 添加 mod_rewrite模块

apache已安装完毕,手动添加mod_rewrite模块
#find . -name mod_rewrite.c //在apache的源码安装目录中寻找mod_rewrite.c文件
#cd modules/mappers/ //进入包含mod_rewrite.c文件的目录
#/usr/share/apache-2.2.11/bin/apxs -c mod_rewrite.c //apxs应指定绝对路径,在你当前正在使用apache的bin目录里
#/usr/share/apache-2.2.11/bin/apxs -i -a -n rewrite mod_rewrite.la
如果没有什么错误的话,应该在你的apache的modules目录中编译出一个mod_rewrite.so文件。
编辑httpd.conf文件,确认httpd.conf中已经包含mod_rewrite.so的加载语句,如下:
LoadModule rewrite_module modules/mod_rewrite.so
这时,你的apache应该已经支持rewrite了。over!
注:完成之后,记得重启服务器apache。

Read More

JSON对象和JSON字符串以及JSON.parse函数的使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!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>
<title>JSON.parse()</title>
<script type="text/javascript">
//示例1:此示例使用 JSON.parse 将 JSON 字符串转换为对象
var jsontext = '{"firstname":"Jesper","surname":"Aaberg","phone":["555-0100","555-0120"]}';//JSON 字符串
var contact = JSON.parse(jsontext);
document.write(contact.surname + ", " + contact.firstname + ", "+ contact.phone);

//示例2:和实例1是一样的效果
var jsontext2 = {"firstname":"Jesper","surname":"Aaberg","phone":["555-0100","555-0120"]};//JSON 对象
//var contact2 = JSON.parse(jsontext2);
document.write("<br /><br />"+jsontext2.surname + ", " + jsontext2.firstname + ", "+ jsontext2.phone);
</script>
</head>
<body>
</body>
</html>

Read More