作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们尝试了'\n'
的几种变体,并尝试了'\r'
,但脚本不断返回行在一起或之间有空格,而不是实际的新线路。这是底部两个问题的脚本:
(function(current, previous, gs, action) {
var eqStr ='cmdb_ci=' + current.getValue('cmdb_ci');
//eqStr='short_description=' + current.getValue('short_description');
//eqStr += '^description=' + current.getValue('description');
eqStr +='^priority=' + current.getValue('priority');
eqStr +='^sys_domain=' + current.getValue('sys_domain');
eqStr +='^company=' + current.getValue('company');
eqStr +='^justification=' + current.getValue('number')
+ '\n' + current.getValue('short_description')
+ '\n' + current.getValue('description') ;
最佳答案
如果您正在构建的字符串最终将被注入(inject)到 DOM 元素中,则必须使用负责解析 DOM 元素的 HTML 解析器熟悉的代码。 HTML 解析器不知道 JavaScript 字符串转义码,如下所示:
let output = "This is\na test.";
document.querySelector("div").innerHTML = output;
let output2 = "This is\nanother test.";
document.querySelector("p").textContent = output2;
<div></div>
<p></p>
对于将成为 DOM 元素一部分的字符串,您需要使用创建换行符的 HTML 标记,<br>
:
let output = "This is<br>a test.";
// innerHTML invokes the parser to parse the supplied string:
document.querySelector("div").innerHTML = output;
let output2 = "This is<br>another test.";
// This won't produce the line break because textContent doesn't invoke the HTML
// parser. Insted, the actual text will be placed in the string.
document.querySelector("p").textContent = output2;
<div></div>
<p></p>
关于javascript - 为什么 '\n' 无法与 ServiceNow 脚本一起使用?未创建新线路,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54411085/
嘿。本周的一个教程,其中一个问题要求通过使用其他函数 formatLine 和 formatList 创建一个函数 formatLines,以格式化行列表。 我的代码是这样的; type Line =
我是一名优秀的程序员,十分优秀!