当前位置:编程学习 > JS >>

JS 中document.URL 和 windows.location.href 的区别

答案:document 表示的是一个文档对象,windows 表示一个窗口对象。
一个窗口下面可以有很多的document对象。每个document 都有 一个URL。

但是,这不是所有的区别。当你ctrl + F5 一个链接 http://www.zhaoxi.net/#server
打印 alert(document.URL ); 和 alert(windows.location.href);
发现,这两个的值不一样,

document.URL : http://www.zhaoxi.net/
windows.location.href :http://www.zhaoxi.net/#server

所以,如果要用 fragment 进行相应的处理的话,最好是用 windows.location.href
否则会出现很奇怪的错误。

上一个:Jquery 获取表单text,areatext,radio,checkbox,select值的代码
下一个:两个select之间option的互相添加操作(jquery实现)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,