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')'>"开发者_JS百科 + lbltext.Text + "</a>"
output is
<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>
how to generate text with double quote in "onclick" from database or any other solution to access 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#
http://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx
精彩评论