简体   繁体   English

javascript output 在 asp.net c# 中带有双引号

[英]javascript output with double quote in asp.net c#

when i generate text from database using datatables in asp.net c#, i can generate this "<a href='javascript:txtreplace('text to replace')'>" + lbltext.Text + "</a>"当我使用 asp.net c# 中的数据表从数据库生成文本时,我可以生成此"<a href='javascript:txtreplace('text to replace')'>" + lbltext.Text + "</a>"

output is output 是

<a onclick='txtreplace('text to replace')'>text</a>

but is in not working on webpage, it is noly working when onclick is in Ddouble quote like <a onclick="txtreplace('text to replace')">text</a>但不能在网页上工作,当onclick<a onclick="txtreplace('text to replace')">text</a>

how to generate text with double quote in "onclick" from database or any other solution to access javascript function如何从数据库或任何其他解决方案中生成带有双引号的文本以访问javascript function

you need to prefix your strings with @ which makes it a verbatim string, then just use " two times您需要在字符串前面加上 @ 前缀,使其成为逐字字符串,然后只需使用 " 两次

@"<a href=""javascript:txtreplace('text to replace')"">" + lbltext.Text  + @"</a>"

or you escape the " with a \或者你用 \ 转义 "

"<a href=\"javascript:txtreplace('text to replace')\">" + lbltext.Text  + "</a>"

here`s some more info about verbatim and regular strings in c#这是有关 c# 中逐字和常规字符串的更多信息

http://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx http://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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