Home > Article > Web Front-end > Getting started with the JavaScript link method (adding a hyperlink to a string)_Basic knowledge
The
link method returns a (italicized) string defined using the HTML a tag attribute. Its syntax is as follows:
Parameter description:
参数 | 说明 |
---|---|
str_object | 要操作的字符串(对象) |
url | 必需。字符串要链接的 URL 地址,完整格式。 |
Tip: This method does not comply with ECMA standards and is not recommended.
link method instance
Run this example, output:
Tip: This method returns the hyperlink string defined using the HTML a tag, even though this method cannot directly change the string into a hyperlink string. If you want to dynamically change the element font to a hyperlink string, you can refer to the following example to extend the link method:
Change the font of page elements to hyperlinks
function addUrl( obj ){
Obj.innerHTML = obj.innerHTML.link( "http://www.jb51.net" );
}
www.jb51.net
In this example, double-click the string www.jb51.net to add a hyperlink to the string.