Jquery 在数据字段之间换行
Jquery break line between data fields
我试图打破字段之间的界限,但我在以前的案例中所做的一切都对我不起作用:“
”“\n”
$(function() {
var body = $(document.body);
for (var i = 0; i `enter code here`< data.length; i++) {
$('<div></div').text(data[i].name + " " + data[i].age + " \n" + data[i].email).appendTo(body);
}
});
换行符与 HTML 无关,您需要使用 <br/>
标签来达到预期的效果。
参见 this MDN 文章。
$('button').click(function(){
$('input').each(function(){
$(this).after('<br>');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<button>fix it up</button>
当然,另一种方法就是使用CSS:
CSS:
input{display:block;}
input {display:block;}
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
我试图打破字段之间的界限,但我在以前的案例中所做的一切都对我不起作用:“
”“\n”
$(function() {
var body = $(document.body);
for (var i = 0; i `enter code here`< data.length; i++) {
$('<div></div').text(data[i].name + " " + data[i].age + " \n" + data[i].email).appendTo(body);
}
});
换行符与 HTML 无关,您需要使用 <br/>
标签来达到预期的效果。
参见 this MDN 文章。
$('button').click(function(){
$('input').each(function(){
$(this).after('<br>');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<button>fix it up</button>
当然,另一种方法就是使用CSS:
CSS:
input{display:block;}
input {display:block;}
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />