【发布时间】:2014-07-31 00:19:25
【问题描述】:
要求:我在网页中有一个带有一些默认值的多行文本区域,我需要更改该值并提交表单。文本区域定义如下。
<textarea id="editorarea" name="_editedtext"
class="editor"
onkeyup="getSuggestions(this.id)"
onclick="setCursorPos(this.id)"
onchange="setCursorPos(this.id)"
rows="20" cols="80">! Lorem ipsum" text is derived
from sections 1.10.32–3 of Cicero's De
finibus bonorum et malorum (On the Ends of Goods
问题:当我从一个字符串为 textarea 设置文本时,它变成如下所示:
<textarea id="editorarea" name="_editedtext"
class="editor"
onkeyup="getSuggestions(this.id)"
onclick="setCursorPos(this.id)"
onchange="setCursorPos(this.id)"
rows="20" cols="80">Lorem ipsum" text is derived<br>from sections 1.10.32–3 of Cicero's De <br>| LPAR Name If Remote:| N/A1<br>\\ <br>! Endpoints<br>finibus bonorum et malorum (On the Ends of Goods'<br>
所以内容变成单行,换行符没有被识别,我试过 "\n" , "
" 都没有工作。
我将我的输入放在一个数组列表中,并将它们转换为单个字符串,如下所示:
public static void createString(){
StringBuilder sb = new StringBuilder();
for(String s : finalModifiedList){
sb.append(s);
sb.append("<br>");
}
finalString =sb.toString();
并设置textarea内容如下
HtmlTextArea erfTextarea = textAreaForm.getTextAreaByName("_editedtext");
erfTextarea.setText(content);
TextArea 字符集是:UTF-8
请告诉我如何使用 htmlunit 输入多行文本
【问题讨论】:
-
你找到解决办法了吗?
标签: java javascript html htmlunit