简体   繁体   中英

Javascript : Return .innerHTML as syntax

I have a little problem here...

This is my code

<html>
 <textarea id="text">
  <h2>Text Here...</h2>
 </textarea>

 <div id="preview">

 </div>
</html>

<script>
  var syntax = document.getElementById("text").innerHTML;
  document.getElementById("preview").innerHTML = syntax;
</script>

The problem is the preview shows <h2>Text Here...</h2> instead of Text Here... with h2 font.

Thanks

Beginner Programmer

Just change your script :

  var syntax = document.getElementById("text").innerHTML; document.getElementById("preview").innerHTML = syntax; 
  <div id="text"> <h2>Text Here...</h2> </div> <div id="preview"> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM