<!-- 没有历史纪录 When a document is replaced, it is also removed from the history object. The replace method loads the specified URL over the current history entry. --> <input type="button" value="location.replace" onclick='location.replace("http://www.yubeinet.com")'><!-- 有历史纪录--> <input type="button" value="location.href" onclick='location.href="http://www.yubeinet.com"'><!--有历史纪录 Loads a new HTML document.--> <input type="button" value="location.assign" onclick='location.assign("http://www.yubeinet.com")'>
那麽什麽是对象呢?如果你学过一些VB的编程,对这个名词一定不会陌生。通俗的说,对象是变量的集合体,对象提供对于数据的一致的组织手段,描述了一类事物的共同属性。 在JavaScript中,可以使用以下几种对象:
1.由浏览器根据web页面的内容自动提供的对象。
2.JavaScript的内置对象,如Date,Math等。
3.服务器上的固有对象。
4.用户自定义的对象。 JavaScript中的对象是由属性和方法两个基本的元素的构成的。对象的属性是指对象的背景色,长度,名称等。对象的方法是指对属性所进行的操作,就是一个对象自己所属的函数,如对对象取整,使对象获得焦点,使对象获得个随机数等等一系列操作。 举个例子来说,将汽车看成是一个对象,汽车的颜色,大小,品牌等叫做属性,而发动,刹车,拐弯等就叫做方法。 可以采用这样的方法来访问对象的属性:对象名称.属性名称,例:mycomputer.year=1996,mycomputer.owner = “me”。 可以采用这样的方法,将对象的方法同函数联系起来:对象.方法名字=函数名字或对象.属性.方法名,例:this.display=display,document.writeln(“this is method”)。 多看或多写一些程序,就会理解对象的方法和属性的含义了!
→
对象.属性.方法location.href="http://www.yubeinet.com";
→
对象.属性
和
location.href="http://www.yubeinet.com";是有区别的,试试下面的代码,请注意工具栏的后退按钮的状态<input type="button" value="location.replace" onclick='location.replace("http://www.yubeinet.com")
'>
<input type="button" value="location.href" onclick='location.href="http://www.yubeinet.com"'>
<input type="button" value="location.assign" onclick='location.assign("http://www.yubeinet.com")
'>
<input type="button" value="location.href" onclick='location.href="http://www.yubeinet.com"'>
如果我是这样呢?区别在什么地方?
href Property还是有区别的,比如alert(location.href)属性和方法是有区别的,楼可以看一下面向对象变成的书
另外,非常谢谢各位的指导!
<input type="button" value="location.replace" onclick='location.replace("http://www.yubeinet.com")'><!-- 有历史纪录-->
<input type="button" value="location.href" onclick='location.href="http://www.yubeinet.com"'><!--有历史纪录 Loads a new HTML document.-->
<input type="button" value="location.assign" onclick='location.assign("http://www.yubeinet.com")'>