Javascript 如果来源 HTML 文本,如何在 child 中显示图像和文本?
Javascript How to show img and text in child if source HTML text?
function addTextArea(){
var textArea = document.createElement("textarea");
textArea.id="tA";
textArea.type="textarea";
textArea.style.position = 'absolute';
textArea.style.top = 120+count*30;
textArea.style.left = 40;
textArea.style.width=2000;
textArea.style.height=2000;
textArea.style.fontSize=20;
textArea.textContent="";
document.body.appendChild(textArea);
document.getElementById("stat2").textContent="Numbers of messages " + count;
}
function readText(){
this.checked=false;
document.getElementById("tA").innerHTML = this.textContent;
}
这是代码片段。
obj this.contett 是 HTML 内含 img 的文本,看起来像:
Mr. Millepied said that he had decided to focus on his own choreography and to return to Los Angeles, where he still directs the L.A. Dance Project.
<br><br><br>
<a href="http://rc.feedsportal.com/r/247390452602/u/31/f/640350/c/34625/s/4d5be40f/sc/13/rc/1/rc.htm" rel="nofollow">
<img src="http://rc.feedsportal.com/r/247390452602/u/31/f/640350/c/34625/s/4d5be40f/sc/13/rc/1/rc.img" border="0">
</a>
<br><br>
我已在标签中插入 space 以显示此字符串。
我怎样才能显示这个字符串的所有元素。现在我只看到了文字。
// this is the html as a string:
var textContent = '<b>bold</b><img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRyabY4muPNtmNIn81wEdmRb9hFlNJuMLLlwX9vvLzucpIpp2Wu"/>';
var count = 1;
function addTextArea(){
var textArea = document.createElement("textarea");
textArea.id="tA";
textArea.type="textarea";
textArea.style.position = 'absolute';
textArea.style.top = 120+count*30;
textArea.style.left = 40;
textArea.style.width=2000;
textArea.style.height=2000;
textArea.style.fontSize=20;
textArea.textContent="";
document.body.appendChild(textArea);
document.getElementById("stat2").textContent="Numbers of messages " + count;
}
function readText(){
this.checked=false;
document.getElementById("tA").innerHTML = textContent;
}
addTextArea();
readText();
<div id="stat2"></div>
function addTextArea(){
var textArea = document.createElement("textarea");
textArea.id="tA";
textArea.type="textarea";
textArea.style.position = 'absolute';
textArea.style.top = 120+count*30;
textArea.style.left = 40;
textArea.style.width=2000;
textArea.style.height=2000;
textArea.style.fontSize=20;
textArea.textContent="";
document.body.appendChild(textArea);
document.getElementById("stat2").textContent="Numbers of messages " + count;
}
function readText(){
this.checked=false;
document.getElementById("tA").innerHTML = this.textContent;
}
这是代码片段。 obj this.contett 是 HTML 内含 img 的文本,看起来像:
Mr. Millepied said that he had decided to focus on his own choreography and to return to Los Angeles, where he still directs the L.A. Dance Project.
<br><br><br>
<a href="http://rc.feedsportal.com/r/247390452602/u/31/f/640350/c/34625/s/4d5be40f/sc/13/rc/1/rc.htm" rel="nofollow">
<img src="http://rc.feedsportal.com/r/247390452602/u/31/f/640350/c/34625/s/4d5be40f/sc/13/rc/1/rc.img" border="0">
</a>
<br><br>
我已在标签中插入 space 以显示此字符串。 我怎样才能显示这个字符串的所有元素。现在我只看到了文字。
// this is the html as a string:
var textContent = '<b>bold</b><img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRyabY4muPNtmNIn81wEdmRb9hFlNJuMLLlwX9vvLzucpIpp2Wu"/>';
var count = 1;
function addTextArea(){
var textArea = document.createElement("textarea");
textArea.id="tA";
textArea.type="textarea";
textArea.style.position = 'absolute';
textArea.style.top = 120+count*30;
textArea.style.left = 40;
textArea.style.width=2000;
textArea.style.height=2000;
textArea.style.fontSize=20;
textArea.textContent="";
document.body.appendChild(textArea);
document.getElementById("stat2").textContent="Numbers of messages " + count;
}
function readText(){
this.checked=false;
document.getElementById("tA").innerHTML = textContent;
}
addTextArea();
readText();
<div id="stat2"></div>