Home  >  Article  >  Web Front-end  >  HTML implements real-time effect viewing function

HTML implements real-time effect viewing function

王林
王林forward
2020-08-14 17:06:144487browse

HTML implements real-time effect viewing function

html realizes the function of viewing the effect in real time

(Recommended tutorial: html tutorial)

The following code will be able to Open a new page to view the effect of our code in the text input field

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>M</title>
    <script type="text/javascript">
      window.onload = function () {
        console.log(document);
        var runBtn = document.getElementById(&#39;input&#39;);
        var runTextArea = document.getElementById(&#39;textarea&#39;);
        runBtn.onclick = function() {
          var oNewWin = window.open(&#39;about:blank&#39;);
          oNewWin.document.write(runTextArea.value); }
      }
    </script>
  </head>
  <body>
    <div>
      <input type=&#39;button&#39; id="input" value=&#39;运行&#39;/><br/>
      <textarea rows=&#39;10&#39; cols=&#39;30&#39; id="textarea" ></textarea>
    </div>
  </body>
</html>

As shown below, the table in the text input box is the content we input

The effect is as follows:

HTML implements real-time effect viewing function

The following picture shows the display effect on the new page

HTML implements real-time effect viewing function

Similarly, we can view the effect on the current page, the code is as follows:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>M</title>
    <script type="text/javascript">
      window.onload = function () {
        var runBtn = document.getElementById(&#39;input&#39;);
        var runTextArea = document.getElementById(&#39;textarea&#39;);
        var result = document.getElementById(&#39;result&#39;);
        runBtn.onclick = function() {
          result.innerHTML = runTextArea.value;
        }
      }
    </script>
  </head>
  <body>
    <div>
      <input type=&#39;button&#39; id="input" value=&#39;运行&#39;/><br/>
      <textarea rows=&#39;10&#39; cols=&#39;30&#39; id="textarea" ></textarea>
    </div>
    <h5>效果展示:</h5>
  <div id="result">
  </div>
  </body>
</html>

The effect is as follows:

HTML implements real-time effect viewing function

Effect display:

HTML implements real-time effect viewing function

The above is the detailed content of HTML implements real-time effect viewing function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete