在textarea中一按回车键就会换行,但是我不希望出现换行,而是让内容直接在一行里显示。
我取出了textarea的innerhtml发现里面根本没有换行符号,但在textarea中就是换行显示。
求解?

解决方案 »

  1.   

    那 lz 的意思是希望在 textarea 中屏蔽回车键?另,在 textarea 中的换行符是“\r\n”,是不可见字符!
      

  2.   

    要实现这样的功能,就不用textarea了
    直接用个input type=text 然后设置一个高度就ok了
      

  3.   

    屏蔽回车键L@_@K
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title> new document </title>
        <meta name="generator" content="editplus" />
        <meta name="author" content="[email protected]" />
        <meta name="keywords" content="" />
        <meta name="description" content="" />
    </head>
    <body>
    <textarea id="myTextArea" rows="20" cols="70"></textarea>
    <input type="button" value="Show" id="showBtn" />
    <script type="text/javascript">
    <!--
        var EnterKeyCode = 13;
        var myTextArea = document.getElementById("myTextArea");
        myTextArea.value = "hehe\r\nhaha"
        myTextArea.onkeydown = function() {
            // 屏蔽回车键!
            if (event.keyCode == EnterKeyCode)
                event.returnValue = false;
        };
        var showBtn = document.getElementById("showBtn");
        showBtn.onclick = function() {
            alert(myTextArea.value.indexOf("\r\n"));
        };
    //-->
    </script>
    </body>
    </html>
    Web 开发常用手册DHTML 参考手册
    http://download.csdn.net/source/308913JScript 语言参考
    http://download.csdn.net/source/308916CCS 样式表中文手册
    http://download.csdn.net/source/304124
      

  4.   

    可以L@_@K
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title> new document </title>
        <meta name="generator" content="editplus" />
        <meta name="author" content="[email protected]" />
        <meta name="keywords" content="" />
        <meta name="description" content="" />
    </head>
    <body>
    <textarea id="myTextArea" rows="20" cols="70"></textarea>
    <input type="button" value="消除换行" id="showBtn" />
    <script type="text/javascript">
    <!--
        var myTextArea = document.getElementById("myTextArea");
        myTextArea.value = "hehe\r\nhaha"
        
        var showBtn = document.getElementById("showBtn");
        showBtn.onclick = function() {
            myTextArea.value = myTextArea.value.replace("\r\n", "");
        };
    //-->
    </script>
    </body>
    </html>
      

  5.   


    但是我用textarea的onkeypress事件怎么不行呢?
      

  6.   

    哎,粗心了。特别感谢yixianggao的回答。
      

  7.   

    我怎么看不见yixianggao的回答呢?还是显示需要先登录....