简体   繁体   English

如何使用jQuery模板转义单引号

[英]How escape single quote with jQuery Template

With jQuery Template I process this string 使用jQuery Template,我处理此字符串

$.tmpl('regionTemplate', {value: key, title: value.name});

if value.name have a single quote, example L'Aquila jQuery template not rendering string 如果value.name有单引号,则示例L'Aquila jQuery模板未呈现字符串

value.name.replace( "'", "\'" )

The syntax $.tmpl('regionTemplate', {value: key, title: value.name}); 语法$.tmpl('regionTemplate', {value: key, title: value.name}); is incomplete. 不完整。 Are you using appendTo or similar? 您使用的是appendTo还是类似的?

 $.tmpl('regionTemplate', {value: key, title: value.name}).appendTo( "#myContainer" );

See archived docs 查看存档的文档

You should not need to escape the '. 您无需转义'。 ${title} in the template will render correctly. 模板中的${title}将正确呈现。 (See this sample , for example). (例如,请参见此示例)。 Otherwise, you need to show your code and template, or create a jsfiddle to show your problem... 否则,您需要显示代码和模板,或创建一个jsfiddle来显示您的问题...

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

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