这可能是一个愚蠢的问题,但如果我有以下HTML代码:
<textarea>This is /n not working</textarea>
它不会显示新行,而是输出换行符号(/ n)。
但是,如果我使用javascript设置textarea的值,它将起作用
$('textarea').val("This is \n working");
所以我不明白\ n角色是如何工作的?
以上是一些小提琴:http://jsfiddle.net/mfLt7/106/
谢谢,
答案 0 :(得分:4)
这是你的回答......
使用 HTML中新行的特殊字符
<textarea id="1">This is my text</textarea>
享受:D
答案 1 :(得分:2)
在HTML格式中,func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let sample = !(DataModel.sampleDetails.isEmpty) ? DataModel.sampleDetails.count : 0
return expandedIndex != nil ?
viewModel.count() + 1 :
viewModel.count()
}
不是新行,也不是/n
。
新行是一个新行(崩溃空白的地方除外,这是HTML的大部分,但textareas是例外之一)。
\n
在JavaScript中,<textarea>This is
not working</textarea>
是一个新行,因此JavaScript将转义序列转换为新行,然后使用实际的新行设置textarea的值。