テキストエリアを使用してユーザー入力を取得しています。行ごとに読みたい。しかし、それは別の行のテキストのコンマ区切りリストを作成したいものを表示していません
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);
});
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>
ここにjsfiddleがあります: