Introduction to JavaScript Link method (add hyperlink to String) _ Basics

Source: Internet
Author: User

The link method returns the (italic) string that is defined using the HTML a label property. The syntax is as follows:

Copy Code code as follows:

Str_object.link (URL)

Parameter description:

Parameters Description
Str_object The string to manipulate (object)
Url Necessary. String to link to the URL address, full format.

Tip: This method does not conform to the ECMA standard and is not recommended for use.

Link Method Instance

Copy Code code as follows:

<script language= "JavaScript" >
var str = "Www.jb51.net";
document.write (Str.link ("http://www.jb51.net"));
</script>

Run the example and output:

Copy Code code as follows:

Www.jb51.net

Tip: This method returns the hyperlink string defined using the HTML a label, which means that the string cannot be changed directly to a hyperlink string. If you want to dynamically change the element font to a hyperlink string, you can extend the link method by referring to the following example:

Change the page element font to a hyperlink

Copy Code code as follows:

<script language= "JavaScript" >

function Addurl (obj) {
obj.innerhtml = Obj.innerHTML.link ("http://www.jb51.net");
}

</script>

<body>
<p ondblclick= "Addurl (this);" >
Www.jb51.net
</p>
</body>

In this example, you can use the mouse to double-click the string www.jb51.net to add a hyperlink to it.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.