格式化字符串以在警告中显示之前添加\ n?

时间:2017-11-14 16:41:37

标签: javascript salesforce apex

我有来自后端的以下字符串,我需要格式化字符串,然后在警告消息中显示它。

我们如何使用Apex代码或使用JavaScript代码?我们如何为\n.添加o

  

尝试将以上内容添加到您的网页,然后加载页面,看看它是否有效。如果没有,你可能有一个bug。具体而言,请:•确保您完全按照显示的内容键入所有内容,:o第三方详细信息•在“请求者所需文档”部分上载以下文档:o提案o相关文档

我正在使用Visualforce页面和Controller。

    <!DOCTYPE html>
    <html>
    <body>

    <h2>JavaScript Alert</h2>

    <button onclick="myFunction()">Try it</button>

    <script>
    function myFunction() {
        alert("Try adding the above to your web page, then load the page and see if it works. 
If it doesn't, you probably have a bug.\n Specifically, please:\n   
• Be sure you typed everything exactly as it appears,:\n     
o Third Party Details   \n• Upload the following documents in the Requestor
Required Documentation section:      \no Proposal     \no Relevant Documentation");
    }
    </script>

</body>
</html>

我已使用object.field.stripHtmlTags();

格式化代码

显示的提示应如下所示。但是如何拆分.o的字符串并使用apex添加\ n? enter image description here

2 个答案:

答案 0 :(得分:1)

试试这个

&#13;
&#13;
alert("Try adding the above to your web page, then load the page and see if it works. If it doesn 't, you probably have a bug.\n\n Specifically, please:\n\no Be sure you typed everything exactly as it appears,: \no Third Party Details\no Upload the following documents in the Requestor Required Documentation section: \no Proposal\ no Relevant Documentation ");
&#13;
&#13;
&#13;

或试试这个

&#13;
&#13;
alert("Try adding the above to your web page, then load the page and see if it works. If it doesn 't, you probably have a bug." + "\n\n Specifically, please:" + "\n\no Be sure you typed everything exactly as it appears" + "\no Third Party Details" + "\no Upload the following documents in the Requestor Required Documentation section" + "\no Proposal" + "\no Relevant Documentation ");
&#13;
&#13;
&#13;

这是根据您带图片的更新帖子编辑的代码

&#13;
&#13;
alert("Try adding the above to your web page, then load the page and see if it works. If it doesn 't, you probably have a bug."+"\n\n Specifically, please:"+"\n\n• Be sure you typed everything exactly as it appears"+ "t\no Third Party Details"+"\n• Upload the following documents in the Requestor Required"+"\n Documentation section" +"\no Proposal"+"\no Relevant Documentation ");
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以尝试使用javascript replace function

例如:

&#13;
&#13;
    var str = "Try adding the above to your web page, then load the page and see if it works. If it doesn't works";
    var newStr = str.replace(".", '.\n');
    alert(newStr);
&#13;
&#13;
&#13;