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:
这是更新的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)
| 归档时间: |
|
| 查看次数: |
6483 次 |
| 最近记录: |