2014-07-03 84 views
-1

我需要将一个mailto元素转换为javascript中的主题元素和正文元素。如何在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>";} 

它输出的html <a href="mailto:[email protected]" ?Subject="Potential" Matter="" New="">

任何想法有什么不对字符串连接?

回答

1

传统的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 
    ); 

编辑好的,我错了js for c#!

您的问题是在HTML属性缺失报价,试试这个:各地href属性

+0

道歉这段代码是在经典ASP页面的javascript部分 – rumi

+0

@Learner好的,我现在明白了。请参阅我的编辑解决方案 – Steve

1

对于concatination &在传统的ASP中使用:

var a = "ehsan " & "sajjad"; 

HERE

+0

道歉这个代码是在传统的ASP页面的JavaScript的一部分

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

注意额外的(逃跑)报价 – rumi