[英]Adding programmatically a span tag with an anchor inside innertext
I have created a span element using: 我使用以下方法创建了一个span元素:
ele= document.createElement(span);
ele.innerText = "bla bla (<a href='https://www.pepe.com'> ble ble </a>) blu blu";
divele.appendChild(ele); #divele is an div in the page
The problem is the tag is not showed as a link, it is showed literally. 问题是标签没有显示为链接,而是按字面显示。
Should be innerHTML
instead of innerText
(since the sting contains HTML in it). 应该是innerHTML
而不是innerText
(因为字符串中包含HTML)。 The span
should be enclosed with single quotes ( ''
) or double quotes ( ""
). 该span
应与单引号(括起来''
)或双引号( ""
)。
var ele= document.createElement('span'); ele.innerHTML = "bla bla (<a href='https://www.pepe.com'> ble ble </a>) blu blu"; var divele = document.getElementById('divele'); divele.appendChild(ele);
<div id="divele"><div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.