[英]Pass HTML as a parameter to a javascript function from c# WCF
I'm creating my HTML code from WCF (c#), when creating the button action I'm passing several parameters one of them will be an HTML code. 我正在从WCF(c#)创建HTML代码,当创建按钮动作时,我传递了几个参数,其中一个将是HTML代码。 The issue that I'm facing when the HTML is containing a double quote " the HTML page thinks that the parameters finish there.
当HTML包含双引号时,我所面临的问题是“ HTML页面认为参数已在此处完成。
I tried to use Encoded html but when sending it from WCF to HTML it decode it automatically 我尝试使用编码的html,但是当将其从WCF发送到HTML时会自动对其进行解码
for example javascript 例如javascript
function generateDocumentMenu(screenName,mainItemId,taskId,subItem, documentMenu)
{
createPopup(decodeURI(documentMenu) ,"","20%","20%","60%","60%");
}
C# C#
screen.Append("<a href='#' id='documentGeneration' class='button popup-toolbar-button document-generation' onclick='generateDocumentMenu(\"" + screenName + "\",\""
+ mainItemId.ToString() + "\",\"" + taskId.ToString() + "\",\"" + subItem + "\", \""+documentMenu +"\");'>");
The issue that i'm facing is with documentMenu for example: 我面临的问题是例如documentMenu:
generateDocumentMenu("user","123","123","user","<div onclick='fn("param");'>aze</div>")
in this example the quotes surrounding param will make a problem i thought about encoding documentMenu variable but it didn't work for me 在此示例中,参数周围的引号会引起我想到的有关编码documentMenu变量的问题,但对我而言不起作用
尝试对插入反斜杠之前的文字引号进行换码
"<div onclick='fn(\"param\");'>aze</div>")
如果您的参数是一个变量,则可以按以下方式编写js:
"<div onclick=\"fn('" + param + "');\">aze</div>"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.