2016-09-30 13 views
0

cleatextを使用してID「css」のテキストエリアのコンテンツをクリアしようとしていますが、動作しません。cleartext Javascript関数が機能しません

<!DOCTYPE html> 

    <html> 
     <head> 
      <meta charset="utf-8"> 
      <title>CSS3 Flexible Box Layout</title> 
      <script type="text/javascript"> 

       function preview() { 
        var textArea = document.getElementById('html'); 
        var div = document.getElementById('preview'); 
        var text = textArea.value; 
        div.innerHTML = text; 
       } 

       function cleartext() { 
        var textareaObject = document.getElementById('css'); 

        console.dir(textareaObject); 
        textareaObject.innerHTML = ""; 
       } 
      </script> 
     </head> 
     <body> 
      <form action="#" method="POST"> 
       <div id="columnsWrapper"> 

        <div class="middleRow"> 

         <textarea id="css" name="css" placeholder="CSS..."></textarea> 
         <br> 
         <textarea id="html" name="html" placeholder="HTML..."></textarea> 

        </div> 
        <div class="middleRow2" id="preview"></div> 
        <div id="button"> 
         <br> 
         <button type="button" class="button" onclick="preview()">Launch</button> 
         <button type="button" class="button" onclick="cleartext()" >Clear</button> 
         <button type="button" class="button">Toggle</button> 
        </div> 
        <div class="empty"></div> 
       </div> 
      </form> 
     </body> 
    </html> 

また、私はtextareaObject.value = nullを使用しようとしました。 どちらも動作しません。

答えて

0

textareaObject.value = ""を試しましたか?これはおそらく動作するはずです。

0

代わりinnerHTML

   function preview() { 
 
        var textArea = document.getElementById('html'); 
 
        var div = document.getElementById('preview'); 
 
        var text = textArea.value; 
 
        div.value = text; 
 
       } 
 

 
       function cleartext() { 
 
        var textareaObject = document.getElementById('css'); 
 

 
        console.dir(textareaObject); 
 
        textareaObject.value = ""; 
 
       }
<!DOCTYPE html> 
 

 
    <html> 
 
     <head> 
 
      <meta charset="utf-8"> 
 
      <title>CSS3 Flexible Box Layout</title> 
 
     </head> 
 
     <body> 
 
      <form action="#" method="POST"> 
 
       <div id="columnsWrapper"> 
 

 
        <div class="middleRow"> 
 

 
         <textarea id="css" name="css" placeholder="CSS..."></textarea> 
 
         <br> 
 
         <textarea id="html" name="html" placeholder="HTML..."></textarea> 
 

 
        </div> 
 
        <div class="middleRow2" id="preview"></div> 
 
        <div id="button"> 
 
         <br> 
 
         <button type="button" class="button" onclick="preview()">Launch</button> 
 
         <button type="button" class="button" onclick="cleartext()" >Clear</button> 
 
         <button type="button" class="button">Toggle</button> 
 
        </div> 
 
        <div class="empty"></div> 
 
       </div> 
 
      </form> 
 
     </body> 
 
    </html>

0

http://plnkr.co/edit/4PWSzqItL55DqhVQV4PC?p=preview

<!DOCTYPE html> 

    <html> 
     <head> 
      <meta charset="utf-8"> 
      <title>CSS3 Flexible Box Layout</title> 
      <script type="text/javascript"> 

       function preview() { 
        var textArea = document.getElementById('html'); 
        var div = document.getElementById('preview'); 
        var text = textArea.value; 
        div.innerHTML = text; 
       } 

       function cleartext() { 
        var textareaObject = document.getElementById('css'); 

        console.dir(textareaObject); 
        textareaObject.value = ""; 
       } 
      </script> 
     </head> 
     <body> 
      <form action="#" method="POST"> 
       <div id="columnsWrapper"> 

        <div class="middleRow"> 

         <textarea id="css" name="css" placeholder="CSS..."></textarea> 
         <br> 
         <textarea id="html" name="html" placeholder="HTML..."></textarea> 

        </div> 
        <div class="middleRow2" id="preview"></div> 
        <div id="button"> 
         <br> 
         <button type="button" class="button" onclick="preview()">Launch</button> 
         <button type="button" class="button" onclick="cleartext()" >Clear</button> 
         <button type="button" class="button">Toggle</button> 
        </div> 
        <div class="empty"></div> 
       </div> 
      </form> 
     </body> 
    </html> 
の使用 value
関連する問題