如何在使用jquery显示错误消息时放置换行符? [英] How to put line break while showing error message using jquery ?
问题描述
如何在使用jquery显示错误消息时放置换行符?
下面是我的代码。
for(var i in testids )
{
singid = singid + testids [i] +,;
}
$(#errmsg)。text(singid);
i希望在单独的行中显示id,即不用逗号作为分隔符我想换线。
i试过
singid = singid + testids [i] +
;
singid = singid + testids [i] +\ n;
singid = singid + testids [i] +\ b;
singid = singid + testids [i ] +
;
但没有运气。
有人知道如何放假吗?
How to put line break while showing error message using jquery ?
below is my code.
for(var i in testids)
{
singid= singid+testids[i]+", ";
}
$("#errmsg").text(singid);
i want to display ids in separate lines, ie instead of comma as a separator i want to put line break.
i tried
singid= singid+testids[i]+"
";
singid= singid+testids[i]+"\n";
singid= singid+testids[i]+"\b";
singid= singid+testids[i]+"
";
but no luck.
anybody knows how to put break ?
推荐答案
(#errmsg)。text(singid);
i希望在单独的行中显示id,即不要使用逗号作为我想要的分隔符换行。
i试过
singid = singid + testids [i] +
;
singid = singid + testids [I] +\\ \\ n;
singid = singid + testids [i] +\ b;
singid = singid + testids [i] +
;
但没有运气。
有人知道如何放假吗?
("#errmsg").text(singid);
i want to display ids in separate lines, ie instead of comma as a separator i want to put line break.
i tried
singid= singid+testids[i]+"
";
singid= singid+testids[i]+"\n";
singid= singid+testids[i]+"\b";
singid= singid+testids[i]+"
";
but no luck.
anybody knows how to put break ?
由于输出是HTML,你需要使用< br>
标记 [ ^ ]:
Since the output is HTML, you need to use the<br>
tag[^]:
singid = singid + testids[i] + "<br>";
但是,您使用 text
方法来显示错误消息,该消息将自动对输出进行HTML编码,包括< br>
标记。
相反,您需要对每条错误消息进行HTML编码,然后使用 html
方法显示错误:
However, you're using the text
method to display the error message, which will automatically HTML-encode the output, including the <br>
tag.
Instead, you'll need to HTML-encode each error message, and then use the html
method to display the error:
function htmlEncode(value){
return
( < span class =code-string>< div />)。text(value).html();
}
...
for ( var i in testids)
{
singid = singid + htmlEncode(testids [i])+ < br>;
}
("<div/>").text(value).html(); } ... for (var i in testids) { singid = singid + htmlEncode(testids[i]) + "<br>"; }
这篇关于如何在使用jquery显示错误消息时放置换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!