Home > Web Front-end > JS Tutorial > How to dynamically create links using js? Tips for dynamically manipulating page elements using js

How to dynamically create links using js? Tips for dynamically manipulating page elements using js

零下一度
Release: 2017-04-26 10:07:15
Original
1745 people have browsed it

This article mainly introduces the method of dynamically creating links with javascript, involving the techniques of dynamically operating page elements with javascript. Friends in need can refer to the following

The example of this article describes the method of dynamically creating links with javascript. Share it with everyone for your reference. The specific analysis is as follows:

Example of dynamically creating links:


<html xmlns="http://www.php.cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>动态添加链接</title>
 <script type="text/javascript">
 function AppendLink() {
  var p = document.getElementById("pMain");
  var linkTmp = document.createElement("a");
  linkTmp.href = "http://www.baidu.com";
  linkTmp.innerText = "百度"; 
  //链接要使用innertText,不能使用value
  p.appendChild(linkTmp);
 }
 </script>
</head>
<body>
 <p id="pMain"></p>
 <input type="button" value="添加链接" onclick="AppendLink()" />
</body>
</html>
Copy after login

The above is the detailed content of How to dynamically create links using js? Tips for dynamically manipulating page elements using js. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template