"."/> ".">
Home > Article > Web Front-end > How to add hyperlinks in JavaScript
In JavaScript, you can use the link method to add a hyperlink, and the syntax format is "string/object to be operated.link(url address)". The "link()" method is used to display a string as a hyperlink. This method returns a string tagged with "3499910bf9dac5ae3c52d5ede7383485".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
JavaScript link method: Add a hyperlink to a string
JavaScript link method
link method returns a (italicized) string defined using the HTML a tag attribute. The syntax is as follows:
str_object.link( url )
Parameter description:
Parameter Description
str_object The string (object) to be operated
url is required. String URL address to link to, in full format.
Tips: This method does not comply with ECMA standards and is not recommended.
link method example
var str = "www.www.3guozi.com"; document.write( str.link( "http://www.cctv.com" ) );
Run this example, output:
http://www.cctv.com
Tips: This method returns the hyperlink string defined using the HTML a tag, that is, use this method and You cannot directly change a 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 page element font to a hyperlink
function addUrl( obj ){ obj.innerHTML = obj.innerHTML.link( "http://www.3guozi.com" ); }
[Recommended learning: JavaScript advanced tutorial】
The above is the detailed content of How to add hyperlinks in JavaScript. For more information, please follow other related articles on the PHP Chinese website!