最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angularjs - Escaping double double quotes in html attributes in Javascript - Stack Overflow

programmeradmin4浏览0评论

I use bootstrap and create html nodes which contain popovers with jQuery. The popovers contain html so that I have problems with the quotes and escaping:

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>';

How can I escape the double quotes inside the attributes => html-attributes? in the data-content attribute correctly?

Edit: I compile the code with angular so that it should also work with it.

I use bootstrap and create html nodes which contain popovers with jQuery. The popovers contain html so that I have problems with the quotes and escaping:

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>';

How can I escape the double quotes inside the attributes => html-attributes? in the data-content attribute correctly?

Edit: I compile the code with angular so that it should also work with it.

Share Improve this question edited Aug 2, 2014 at 10:26 daniel asked Aug 2, 2014 at 10:19 danieldaniel 35.7k40 gold badges107 silver badges162 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 19

If it is HTML, you can use HTML entities to escape characters that might be interpreted otherwise. For example, &quot; will be displayed as " in HTML attributes:

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

Proof of concept: http://jsfiddle.net/teddyrised/5X5Ye/

Refer to W3C's HTML entities chart for more information: http://dev.w3.org/html5/html-author/charref

发布评论

评论列表(0)

  1. 暂无评论