且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在使用jquery显示错误消息时放置换行符?

更新时间:2022-05-10 09:13:42

(#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


< 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>"; }