用split把字符按“\n”分为数组,再读取第3项就行了。var s = "A\nBB\nCD\nE";
alert(s.split("\n")[2]);

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    <script language="JavaScript">
    function fetch(str, pos){
    var arrText = str.split("\n");
    if( arrText && pos > 0 && pos <= arrText.length ){
    return arrText[pos-1];
    }
    return null;
    }
    </script>
    <body>
    <form>
    <textarea rows="5" id="text1"></textarea>
    <input type="text" id="txtPos" value=1>
    <input type="button" value="test" onclick="alert( fetch(text1.value, txtPos.value));">
    </form>
    </body>
    </html>
      

  2.   


    2楼的没问题啊,因为换行总是用\r\n或\n的,所以文本是谁发来的都没问题的