文档对象 文档对象: document 包含了当前文档的信息,提供了向用户“显示HTML输出”的方法。 锚点对象 锚点对象: Anchor 网页中的锚点均会被自动看作锚点对象,并依顺序,分别表示为document.anchors[0],document.anchors[1]... 定义锚点对象的格式: 字串.anchor(属性) 锚点对象的属性: name 锚点名称 text 锚点字串 链接对象 链接对象: Link 网页中的链接均会被自动看作链接对象,并依顺序,分别表示为document.links[0],document.links[1]... 定义链接对象的格式: 字串.link(属性) 链接对象的属性: hash URL中的锚点名称 host 主机域名或IP地址 hostname URL中的host+port href 完整的URL字串 pathname URL中path部分 port URL中端口部分 protocol URL中通讯协议部分 search URL中查询字串部分 target 代表目标的窗口 text 表示A标签中的文字 x 链接对象的左边界 y 链接对象的右边界 链接对象的方法: handleEvent(事件) 激活对某事件的处理程序。 链接对象的事件处理程序: onClick onDbClick onKeyDown onKeyPress onKeyUp onMouseDown onMouseUp onMouseOver onMouseOut 例1: <Script> function linkGetter() { msgWindow = open('','','width=250,height=200') msgWindow.document.write("共有" + document.links.length + "个搜索引擎") for (var i = 0; i < document.links.length; i++) { msgWindow.document.write("<LI>"+document.links[i]) } } </Script> 常用的搜索引擎:<BR> <A HREF="http://www.yam.org.tw/">蕃薯藤</A> <A HREF="http://www.kimo.com/">奇摩</A> <A HREF="http://chinese.yahoo.com/">雅虎</A> <A HREF="http://gais.cs.ccu.edu.tw/">盖世</A> <A HREF="http://www.openfind.com.tw/">网擎</A> <A HREF="http://www.dreamer.com.tw/">梦想家</A><BR> <INPUT TYPE="button" VALUE="网址一览" onClick=linkGetter()> 位置对象 位置对象: Location 用来代表特定窗口的URL信息。 格式: location.属性 location.方法(参数) URL的格式: protocol//host:port/path#hash?search URL的种类: javascript: javascript程序代码 view-source: 显示源代码 http: file: ftp: mailto: news: gopher 位置对象的属性: hash 锚点名称 host 主机名称 hostname host:port href 完整的URL字符串 pathname 路径 port 端口 protocol 协议 search 查询信息 位置对象的方法: reload() 重新加载 replace(网址) 用指定的网页取代当前网页 例1: 按下按钮前往「文哥网络技术学习网」<P> <INPUT TYPE="button" VALUE="走吧!" onClick="location.href='http://www.hubert.idv.tw/'"> 例2: <FONT COLOR="red" onClick="location='http://www.hubert.idv.tw/'"> 文哥网络技术学习网</FONT><P> <FONT COLOR="blue" STYLE="cursor:hand" onClick="location='http://www.hubert.idv.tw/'"> 文哥网络技术学习网</FONT> 例3: <Script> var sec = 5; function countDown() { if (sec > 0) { num.innerHTML = sec--; } else location = "http://www.hubert.idv.tw/"; } </Script> <BODY onLoad="setInterval('countDown()', 1000)"> <CENTER> 文哥网络技术学习网 <H2>http://www.hubert.idv.tw/</H2> 五秒钟后自动带你前往<BR> <FONT ID="num" SIZE="7" FACE="impact">5</FONT> 例4: <A HREF="#" onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.hubert.idv.tw/');"><FONT COLOR="red"><U>设为首页</U></FONT></A><P> <A HREF="javascript:window.external.AddFavorite('http://www.hubert.idv.tw/','文哥网络技术学习网');"><FONT COLOR="red"><U>加入收藏</U></FONT></A>
javascript中document,link,anchor,location对象的使用方法
最新推荐文章于 2023-08-04 08:40:02 发布