- 链接对象:
网页中的链接均会被自动看作链接对象,并依顺序,分别表示为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()>