简体   繁体   中英

how to concatenate string in javascript

I need to convert a mailto element to have subject and body element in a javascript.

var matterDetail = "?Subject=Potential New Matter";
try{strContact = strContact + "<TD><A href=mailto:" +  EMailNode.item(0).firstChild.nodeValue +matterDetail +">" +  EMailNode.item(0).firstChild.nodeValue + "</A></TD>";}

This outputs the html to <a href="mailto:some@email.com" ?Subject="Potential" Matter="" New="">

Any ideas what is wrong with string concatenation?

For concatination & is used in classic asp:

var a = "ehsan " & "sajjad";

See HERE

Classic asp is not written in c#, so i dont know what you are using, but as it seems you are using c#, i would use string.format:

strContact += string.Format(
    "<td><a href=\"mailto:{0}{1}\">{2}</a></td>", 
    EMailNode.item(0).firstChild.nodeValue,
    matterDetail, 
    EMailNode.item(0).firstChild.nodeValue
    );

EDIT ok, i mistook js for c#!

Your problem is missing quotes in the html attributes, try this:

strContact += "<td><a href=\"mailto:" +  EMailNode.item(0).firstChild.nodeValue +matterDetail +"\">" +  EMailNode.item(0).firstChild.nodeValue + "</a></td>";

Note the extra (escaped) quotes around the href attribute

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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