it should be changed into "\r" not "\n"and you should get the textarea's value by using this method belowdocument.getElementsByTagName("textarea")[0].innerHTML

解决方案 »

  1.   

    document.getElementsByTagName("textarea")[0].innerHTML
      

  2.   

    innerHTML啊,我去试试看能不能解决这个问题,貌似可以。解决后结贴^^
      

  3.   

    貌似不能?
    document.getElementsByTagName("textarea")[0].innerHTML  = "asd
    dsa";
    出错啊怎样才能附多行值给变量?
    或者怎样取得textarea的值为单行?下面在ff下没用吧?
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script language=javascript>
    function as(){
    alert(document.getElementsByTagName("textarea")[0].innerHTML);
    }

    </script>
    </head>
    <body>
    <textarea id="ta1" name="ta1" COLS="70" ROWS="8" ></textarea>
    <input type="button" onclick="as()">
    &#010;
    </body>
    </html>
      

  4.   

    no.. the error is occurred by the document.getElementsByTagName("textarea")[0]
      

  5.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
    <body>
    <textarea id="ta1" name="ta1" COLS="70" ROWS="8" ></textarea>
    <input type="button" onclick="as()">
    &#010;
    <div id="div1">
    <script language=javascript>
    function as(){
    var txt=document.getElementById("ta1").value;
    alert(escape(txt));
    var div1=document.getElementById("ta2");
    ta2.value=txt
    }

    </script>
    </div1>
    <textarea id="ta2" name="ta2" COLS="70" ROWS="8" ></textarea>
    </body>
    </html>用replace替换就对了,试着输入不同格式的内容,看看上面alert之后会显示什么就明白了
      

  6.   

    sorry, maybe you can try this.<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script language="javascript">var node;function as(){
    node=document.getElementById("ta1");
    alert(node.value);
    node.value="new";
    }</script>
    </head>
    <body>
    <textarea id="ta1" name="ta1" COLS="70" ROWS="8" ></textarea>
    <input type="button" value="got the value" onclick="as()">
    &#010;
    </body>
    </html>
      

  7.   

    结果自己解决了
    当textarea多行时,换行自动有个\r\n,只是显示不出来
    只要在取值后把其转了就行了谢谢大家,顶者有分