如何将html <br/>标签添加到javascript中

时间:2015-03-17 08:36:46

标签: javascript jquery html mailto

我有一个按钮,当点击时打开电子邮件并用变量填充正文。这看起来太乱了,因为它们都出现在一条线上。我可以在每个变量之间插入一个br标签,以便它们出现在一个新行上吗?

感谢。这是代码:

$("#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); 
        });

我在想:

$("#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); 
    }); 

2 个答案:

答案 0 :(得分:3)

使用%0D%0A的ASCII代码,如下所示:

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); 

严格来说,白色空间也应该被替换。使用%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); 

答案 1 :(得分:2)

尝试这样的事情

            $("#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
                });

它可能有用......(让我知道它有效!)