【发布时间】:2016-02-09 05:59:21
【问题描述】:
以下小提琴允许将文本粘贴到 <textarea> 并在按钮单击时生成段落。
是否可以在下面的代码中创建两个下拉列表<select></select>,一个将段落的颜色更改为<p> 为用户单击时选择的任何颜色,另一个更改大小动态文本?
附件是Fiddle。如果小提琴可以更新,那将非常有帮助,因为我还是编码新手。
HTML:
<div>
<div id="text_land" style="border:1px solid #ccc; padding:25px; margin-bottom:30px;">xzxz</div>
<textarea style="width:95%;"></textarea>
<button>Go</button>
Javascript:
$(function () {
$('button').on('click', function () {
var theText = $('textarea').val();
var i = 200;
while (theText.length > 200) {
console.log('looping');
while (theText.charAt(i) !== '.') {
i++;
}
console.log(i);
$("#text_land").append("<p>" + theText.substring(0, i+1) + "</p>");
theText = theText.substring(i+1);
i = 200;
}
$('#text_land').append("<p>" + theText + "</p>");
})
})
谢谢!
【问题讨论】:
标签: javascript jquery html textarea paragraph