[英]As you can see I am trying to create a link elements?
<html>
<head>
<link
href="css/styles.css"
rel="stylesheet">
</head>
<body onload="createImg()">
<h1>My Website</h1>
<p>This is my first
website</p>
<div id='working_area' >
</div>
<script>
function createImg(){
var img=document.getElementById("working_area");
img.innerHTML="<a src='https://www.google.com'>google</a>";
}
</script>
</body>
</html>
So I want to create a hyperlink using this method and not using create elements method Why?所以我想使用这种方法创建一个超链接而不是使用创建元素方法为什么? Because I want to create a html editor因为我想创建一个html编辑器
** Is it possible ? **有可能吗? ** **
Here is the image of results.这是结果的图像。 The link doesn't working.该链接不起作用。
use href
attribute rather than src
for a
tag.使用href
属性,而不是src
的a
标签。
<html> <head> <link href="css/styles.css" rel="stylesheet"> </head> <body onload="createImg()"> <h1>My Website</h1> <p>This is my first website</p> <div id='working_area' > </div> <script> function createImg(){ var img=document.getElementById("working_area"); img.innerHTML="<a href='https://www.google.com'>google</a>"; } </script> </body> </html>
In HTML the <a>
tag defines a hyperlink and the <href>
attribute indicates the link destination.在 HTML 中, <a>
标签定义了一个超链接, <href>
属性表示链接目的地。 <src>
is not part of it. <src>
不是它的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.