简体   繁体   English

如何添加HTML <br> 标记成javascript

[英]How to add html <br> tags into javascript

I have a button that when clicked opens email and fills the body with variables. 我有一个按钮,当单击该按钮时,将打开电子邮件并用变量填充正文。 This looks too messy though as it all appears on one line. 这看起来太混乱了,因为它们全部显示在一行上。 Could I just chuck in a br tag inbetween each variable so they appear on a new line? 我可以在每个变量之间插入一个br标签,使它们出现在新行上吗?

Thanks. 谢谢。 Here is code: 这是代码:

$("#buttonLink").click (function() {
            window.open('mailto:sales@beauxcadeaux.co.uk?subject=My Frame&body=My frame Type: ' + frameType + ' My Frame Background: ' + frameBackground + ' My text: ' + yourText + ' My Text design: ' + textDesign); 
        });

I'm thinking something like: 我在想类似的东西:

$("#buttonLink").click (function() {
        window.open('mailto:sales@beauxcadeaux.co.uk?subject=My Frame&body=My frame Type: ' + frameType + <br> + ' My Frame Background: ' + frameBackground + <br> + ' My text: ' + yourText + <br> +' My Text design: ' + textDesign); 
    }); 

Use the ASCII code which is %0D%0A , like this: 使用ASCII代码%0D%0A ,如下所示:

window.open('mailto:sales@beauxcadeaux.co.uk?subject=My Frame&body=My frame Type: ' + frameType +'%0D%0A My Frame Background: ' + frameBackground + '%0D%0A My text: ' + yourText + '%0D%0A My Text design: ' + textDesign); 

Strictly speaking should the white spaces also be replaced. 严格来说,也应该替换空白。 Use the ASCII code which is %20 , like this: 使用%20的ASCII代码,如下所示:

window.open('mailto:sales@beauxcadeaux.co.uk?subject=My%20Frame&body=My%20frame%20Type:%20' + frameType +'%0D%0A%20My%20Frame%20Background:%20' + frameBackground + '%0D%0A%20My%20text:%20' + yourText + '%0D%0A%20My%20Text%20design:%20' + textDesign); 

try some thing like this 尝试这样的事情

            $("#buttonLink").click (function() {
    //try this 

        var brtag= document.createElement("br");

    //then 
    brtag.id = "your_id"
     brtag.setAttribute("class", "your_class");

    //and so on

//then do rest of your stuffs
                });

it might work ...(do let me know it it works !) 它可能起作用...(让我知道它起作用了!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM