[英]how to concatenate string in javascript
I need to convert a mailto element to have subject and body element in a javascript. 我需要将mailto元素转换为在javascript中具有subject和body元素。
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="">
这
<a href="mailto:some@email.com" ?Subject="Potential" Matter="" New="">
html输出到<a href="mailto:some@email.com" ?Subject="Potential" Matter="" New="">
Any ideas what is wrong with string concatenation? 任何想法字符串连接有什么问题吗?
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: 经典的ASP不是用C#编写的,所以我不知道您在使用什么,但是似乎您正在使用C#,所以我会使用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#! 编辑好吧,我误以为C#的JS!
Your problem is missing quotes in the html attributes, try this: 您的问题是html属性中缺少引号,请尝试以下操作:
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 请注意href属性周围的多余(转义)引号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.