[英]JavaScript: modify contents of multi-line input
I have a multi-line input box and I'm trying to output to another text box using document.getElementById('output').value
when the button on the form is pressed. 我有一个多行输入框,当我按下表单上的按钮时,我试图使用
document.getElementById('output').value
输出到另一个文本框。
Basically what I want to do is wrap [img] tags around every line. 基本上,我想做的是将[img]标签包裹在每一行中。 Which function do I use to do this?
我该使用哪个功能? I have googled this to death but I can't find anything explaining it.
我用谷歌搜索将其杀死,但找不到任何解释。
eg. 例如。
input of: 输入:
picture1.jpg picture1.jpg
picture2.jpg picture2.jpg
picture2.jpg picture2.jpg
outputs to: 输出到:
[img]picture1.jpg[/img] [IMG] picture1.jpg [/ IMG]
[img]picture2.jpg[/img] [IMG] picture2.jpg [/ IMG]
[img]picture2.jpg[/img] [IMG] picture2.jpg [/ IMG]
I've set this up to make it easier for help: 我进行了设置,以使其更容易获得帮助:
<SCRIPT LANGUAGE="JavaScript">
function testResults (form) {
var Images = form.images.value;
document.getElementById('output').value = Images;
}
</SCRIPT>
<form name="form" method="post" action="">
<textarea name="images" cols="40" rows="10" id="images"></textarea>
<br>
<br>
<INPUT TYPE="button" NAME="button" Value="[IMG]" onClick="testResults(this.form)">
<br>
<br>
<label>
<textarea name="output" id="output" cols="40" rows="10"></textarea>
</label>
</form>
Try something like: 尝试类似:
data = data.split('\n')
.map(function (line) {
return '[img]' + line + '[/img]';
})
.join('\n');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.