Bootstrap popover中单引号/双引号的基本HTML/JavaScript混淆



尝试在Bootstrap popover中添加链接(转到"帮助"页面)。看到了在popover中获取链接的各种复杂解决方案,但有人提出了一个简单的onclick window.open。这似乎是一个有趣的解决方案,但我陷入了双引号/单引号的地狱。

我使用的是phpStorm,它在突出显示错误方面做得很好。我正在尝试的是:

<i class="explain fa fa-question-circle text-primary"
data-toggle="popover" data-trigger="focus" tabindex="0" title="Popover title"
data-content="And here's some amazing content. It's very engaging.<a href='#' 
onclick='window.open("http://www.google.com/");' title='test add link'>
link to content</a> Right?"></i>

这是我复制的原件:

<a href="#" onclick="window.open('http://www.google.com/');"> link </a>

我的问题是,当我将single切换为double时,我在("http://www.google.com/");的初始"处得到一个错误,并且有一个未闭合的标记。

请问我有什么不明白的。

尝试使用&quot;在HTML属性中:

<i class="explain fa fa-question-circle text-primary"
data-toggle="popover" data-trigger="focus" tabindex="0" title="Popover title"
data-content="And here's some amazing content. It's very engaging.<a href='#' 
onclick=&quot;window.open('http://www.google.com/');&quot; title='test add link'>
link to content</a> Right?"></i>

比较一下:如何正确地转义html属性中的引号?

您需要将data-html="true"与其他数据一起包含-*

这是jsFiddle

最新更新