代码如下:巨简单的代码,但是尝试了一下午也不知道问题出现在哪里,是个html文件,忘各位大哥建个页面跑下,帮帮小弟,不胜感激。
<!DOCTYPE HTML>
<html>
<body>
     <form method="post" name="myform">
         <fieldset>
         <legend>Question 0:</legend>
         <label>What is your name?&nbsp;</label><br>
            
         <div><textarea name="answer0" id="answer0" rows="" cols=""></textarea></div>           
    </fieldset>
            <input type="button" style="width: 100px" onClick="javascript:localstore()" value="Done" title="Submit the symptom"/>
        </form>
</body>
    <script type="text/javascript" defer=true>
        function localstore(){
         document.write("Start");
        var answerContent = document.getElementById("answer0");
        alert(answerContent);
}
</script>
</html>

解决方案 »

  1.   

    取掉document.write("Start"); 
    function localstore(){
                var answerContent = document.getElementById("answer0").value;
                alert(answerContent);
            }
      

  2.   

    document.getElementById("answer0").value;
      

  3.   

    去掉 document.write("Start");
    当页面加载完成后,document.write 将产生新的 document
    也就是没有了 textarea,如何能取到数据?
    这一点你自己也可从页面的变化中看出