繁体   English   中英

在Javascript中转义html属性中的双引号

[英]Escaping double double quotes in html attributes in Javascript

我使用bootstrap并创建包含jQuery弹出窗口的html节点。 弹出窗口包含html,所以我有引号和转义问题:

var content = '<input type="text" ng-model="test1" />';
var txt =     '<button type="button" data-container="body" ' +
                     'data-toggle="popover" title="myTitle" data-html="true" '+
                     'data-content="'+content+'">Click</button>';

如何在attributes => html-attributes中转义双引号? 在数据内容属性中正确吗?

编辑:我使用angular编译代码,以便它也可以使用它。

如果是HTML,则可以使用HTML实体来转义可能以其他方式解释的字符。 例如, &quot; 将显示为"在HTML属性中:

var content = '<input type=&quot;text&quot; ng-model=&quot;test1&quot; />';

概念证明: http//jsfiddle.net/teddyrised/5X5Ye/

有关更多信息,请参阅W3C的HTML实体图表: http//dev.w3.org/html5/html-author/charref

暂无
暂无

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

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