【发布时间】:2015-05-20 00:12:02
【问题描述】:
string mystring == "<input class=\"success\" type=\"button\" id=\"Delegate_New_btn\" value=\"New\" onclick=\"location.href="+mylocation+"'/>";
我有一个像上面这样的字符串。
问题是当我将它的 innerHTML 转换为如下所示的 div 时,它会显示不正确的语法错误:
document.getElementById("id").innerHTML=mystring;
我需要的是:
<input type="button" value"somevalue" onclick="location.href='mylocationurl'"/>
我不知道如何将这个单引号包含在双引号中。我试过反斜杠方法,但我也没有实现。
注意:我已经在我的服务器端 C# 中定义了这个并将它传递给客户端 请帮我解决这个问题。
更多信息
VM.Custombuttons_tag = "<td><input class=\"btn btn-mini btn-success\" type=\"button\" id=\"Delegate_New_btn\" value=\"New\" onclick='location.href=\'" + string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~")) + "/ABC/Delegate/AssignListUserLevel?PeriodId=0'/></td>";
这是我的完整代码,VM 是一个方法,Custombuttons_tag 是字符串,所以当我运行我的代码时,它会将代码内部 HTML 转换为 div,并显示一些不正确的语法错误
【问题讨论】:
-
我认为您的问题与双引号无关。不知道你的意思是:“我已经在我的服务器端 C# 中定义了它并将它传递给客户端”。您通过什么方式将其传递给客户端?请显示该代码。第一行代码是C#吗?对于这个
document.getElementById("id").innerHTML=string;,string定义在哪里?mylocationurl在哪里定义?请提供所有相关代码! -
@KJPrice 检查我的更新代码
标签: javascript html string quotes