hrefattribute is any string or a property of an existing object.
method of
描述
use the link method with the write or writeln methods to programatically create and display a hypertext link in a document. create the link with the link method, then call write or writeln to display the link in a document.
in the 语法, the linktext string represents the literal text that you want the user to see. the hrefattribute string represents the href attribute of the <a> tag, and it should be a valid url. each section of a url contains different information. see the location object for a 描述 of the url components.
links created with the link method become elements in the links array. see the link object for information about the links array.
例子
the following example displays the word "netscape" as a hypertext link that returns the user to the netscape home page:
var hottext="netscape"
var url="http://www.netscape.com"
document.open()
document.write("click to return to " + hottext.link(url))
document.close()
the previous example produces the same output as the following htm:
click to return to <a href="http://www.netscape.com">netscape</a>
相关
link object (links array)
a piece of text or an image identified as a hypertext link. when the user clicks the link text, the link hypertext reference is loaded into its target window.
语法
to define a link, use standard htm 语法 with the addition of the onclick and onmouseover event handlers:
<a href=http://dev.csdn.net/article/10/locationorurl [name="anchorname"] [target="windowname"] [onclick="handlertext"] [onmouseover="handlertext"]> linktext </a>href=locationorurl identifies a destination anchor or url. see the location object for a 描述 of the url components.
name="anchorname" specifies a tag that becomes an available hypertext target within the current document. if this attribute is present, the link object is also an anchor object. see anchor for details.
target="windowname" specifies the window that the link is loaded into. windowname can be an existing window; it can be a frame name specified in a <frameset> tag; or it can be one of the literal frame names _top, _parent, _self, or _blank; it cannot be a javascript expression (for example, it cannot be parent.framename or windowname.framename).
linktext is rendered as a hypertext link to the url.
you can also define a link using the link method.
to use a link object's properties:
document.links[index].propertynameindex is an integer representing a link object.