2

このスクリプトはDIV、ボタンがクリックされたときにタグを取得し、コンテンツを含む新しいページを開きます。textareaしかし、ユーザーが何かを入力した後に内容を表示したい.

何か案は?コードは次のとおりです。

<script type="text/javascript">
  var win=null;
  function printIt(printThis)
  {
    win = window.open();
    self.focus();
    win.document.open();
    win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
    win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
    win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
    win.document.write(printThis.innerHTML);
    win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
    win.document.close();
    win.print();
  }
</script>
</head><body>
    
  <div id="activity5">
    <blockquote>
      <table border="0" cellpadding="3">
      </table>
      <form id="form4" name="form1" method="post" action="">
      <textarea name="Activity1a4" cols="80" rows="15" class="s23" id="ta1"></textarea>
      <p>
        <input name="print4" type="submit" id="print4" value="Print" onclick="printIt(document.getElementById('activity5')); return false"/>
          * Retain this learning activity as part of your portfolio of evidence.</p>
      <p>Check your findings with the correct answer in the back of this Learner Resource under 'Learning activity answers'.</p>
      </form>
    </blockquote>
  </div>
</body>

4

2 に答える 2

2

テキストエリアのコンテンツは、.valueではなく、で取得し.innerHTMLます。

つまり、activity5innerHTMLを取得しても、子テキストエリアに入力されたテキストは含まれません。そのテキストを含める場合は、textareaでそのテキストを個別に取得し.value、新しいページの新しいテキスト領域に挿入する必要があります。

于 2012-05-07T00:36:46.793 に答える
2

textareaのコンテンツを属性とは別に取得してからvalue、同じ方法で明示的に設定する必要があります。その方法の例については、http://jsfiddle.net/EPvWV/をご覧ください。

于 2012-05-07T00:40:28.997 に答える