如何在HTML标记属性中包含换行符?
例如:
<a href="somepage.html" onclick="javascript: foo('This is a multiline string.
This is the part after the newline.')">some link</a>
编辑:对不起,糟糕的例子,如果标签碰巧不在javascript中怎么办,比如:
<sometag someattr="This is a multiline string.
This is the part after the newline." />
javascript Edit2Javascript:原来字符串中的换行符不是我的问题,而是我调用的函数。FWIW,"
“可用于超文本标记语言属性的换行。
发布于 2009-06-11 22:04:42
根据我对HTML标准的记忆,字符实体在属性中工作,所以这可能是可行的:
<sometag someattr="This is a multiline string. This is the part after the newline." />
我不确定你想要的“换行符”是否应该是
(\n)或
(\r\n),我不确定浏览器是否会按照您想要的方式解释它。
你为什么需要它?您试图通过在HTML标记属性中添加换行符来解决什么具体问题?
发布于 2009-06-11 21:52:45
要包含多行值,只需在编辑器的下一行上继续html属性的文本,例如
<input type="submit" value="hallo
hallo">
会把第二个哈罗放在第一个下面
发布于 2009-06-11 21:49:12
一般而言,属性中的换行符将被保留,因此第二个示例可以很好地工作。你试过了吗?你能举一个具体的例子来说明你在使用它时遇到的问题吗?
作为测试,看看这个:-
<a href="somepage3.html" onclick="javascript: alert(this.getAttribute('thing'))" thing="This is a multiline string.
This is the part after the newline.">some link</a>
警报在属性中包含换行符。
https://stackoverflow.com/questions/983856
复制相似问题