javascript常用方法--备忘

location常用方法

location.hash 设置或获取 href 属性中在井号“#”后面的部分。  
location.search 设置或获取 href 属性中跟在问号?后面的部分。

location.hostname 设置或获取域名

location.reload 重新加载当前页面,(true)从服务器重新加载,(false)从缓存中重新加载

document.frames('ifrmname').location.reload()
iframepage.location.reload()//注意这个不用document.getElementById("")的方式,直接把元素id写上,只有iframe有这种写法
window.onhashchange=function () {
    //这是html5的方法,当在浏览器里输入hash值得时候点击回车才有响应,默认是不会响应的
}

js中substring和substr的用法
http://www.cnblogs.com/wz327/archive/2010/04/11/1709433.html

数组转字符串数组

var result=[1,2,3];
var str=JSON.stringify(result);

这时str就会变成'[1,2,3]',没想到这个JSON.stringify这么强大吧

 

还有第二种方法,

var result=[1,2,3];

var str=result.join('');

var obj='['+str+']';

 

还有第三种方法,

var result=[1,2,3];

var str=result.toString();

var obj='['+str+']';

空字符串和空的样子

这个是为null

判断一个json是否为空使用for in,判断数组和字符串为空,使用length判断

原文地址:https://www.cnblogs.com/masita/p/4500857.html