逐行读取 textarea 中的文本

ALB*_*LBI 3 html javascript jquery textarea

我正在使用 textarea 来获取用户输入。并想逐行阅读。但它没有显示任何我想在不同行中制作一个逗号分隔的文本列表

JS:

$('input[type=button]').click( function() {
    string = document.getElementById("hi").val();
    alert(string); 
    var html="";
    var lines = $('#id').val().split('\n');
    for(var i = 0;i < lines.length;i++){
        //code here using lines[i] which will give you each line
        html+=lines[i];
        html+=",";
    }
    $("#inthis").html(string);
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<textarea id="hi" name="Text1" cols="40" rows="5" placeholder="enter one wdg in one line" ></textarea>

<input type="button" value="test" />
<div id="inthis"></div>
Run Code Online (Sandbox Code Playgroud)

这是jsfiddle:

http://jsfiddle.net/pUeue/1077/

nik*_*nik 5

这是更新的js...

演示小提琴

$('input[type=button]').click(function () {
    var html = "";
    var lines = $('#hi').val().split('\n');
    for (var i = 0; i < lines.length; i++) {
        //code here using lines[i] which will give you each line
        html += lines[i];
        html += ",";
    }
    html = html.substring(0,html.length-1);
    $("#inthis").html(html);
});
Run Code Online (Sandbox Code Playgroud)