今天,我遇到了最奇怪的问题之一。我有一个带有打开弹出窗口的自定义操作的列表。它适用于英语和荷兰语,但在法语中,弹出窗口永远不会打开。
问题是,资源文件用法语说:看单引号
<data name="Message_GenerateSponsoringAgreement_SUCCESS" xml:space="preserve">
<value>Création de l'accord de sponsoring terminée avec succes.</value>
</data>
自定义操作如下:请注意,在 javascript 中,您使用单引号传递变量。我尝试用以下内容替换单引号:
'
但它不起作用。我尝试用 '
替换它。并且它没有显示在自定义操作上
<UrlAction Url="javascript:function process(){var site='{SiteUrl}';OpenPopUpPageWithTitle(site+'/_layouts/spnl.sponsoring/GenerateSponsoringAgreement.aspx?ListID={ListId}&ID={ItemId}&Source=' + window.location, RefreshOnDialogClose, 400, 200,'$Resources:SPNLSponsoring,CustomAction_GenerateSponsoringAgreement_Title;');}; process();" />
最佳答案
在 C# 中,您可以使用 System.Web.HttpUtility.JavaScriptStringEncode() 调用,该调用将在单引号前面加上反斜杠。
http://msdn.microsoft.com/en-us/library/system.web.httputility.javascriptstringencode.aspx
来自上面的 URL:
此方法对字符串进行编码。例如,单引号和双引号在编码字符串中包含为\' 和\"。
关于javascript - 使用 JavaScript 对资源文件中的单引号进行编码以实现自定义操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12861675/