"."> How to add hyperlinks in JavaScript-JS Tutorial-php.cn

How to add hyperlinks in JavaScript

醉折花枝作酒筹
Release: 2021-06-15 14:59:17
Original
10124 people have browsed it

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 "".

How to add hyperlinks in JavaScript

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 )
Copy after login

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" ) );
Copy after login

Run this example, output:

http://www.cctv.com
Copy after login

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" ); }
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!