[英]Bootstrap 3 Popover with function for content
Bootstrap 3 provides a Popover that I'm trying to use. Bootstrap 3提供了我要使用的Popover 。 The docs say that the
data-content
may be either a string or a function. 文档说
data-content
可以是字符串或函数。 However, I seem unable to set the content to a function: 但是,我似乎无法将内容设置为一个函数:
<button type="button"
class="btn btn-lg btn-danger"
data-toggle="popover"
title="Popover title"
data-content="my_function();">
Click to toggle popover
</button>
And here's the JavaScript: 这是JavaScript:
$(function () {
$('[data-toggle="popover"]').popover()
})
function my_function(){
return "This is my popover's content";
}
You can try the JSFiddle . 您可以尝试JSFiddle 。
I've also tried variations like data-content="javascript:my_function();"
我还尝试过类似
data-content="javascript:my_function();"
. 。 I'm not sure if my syntax is just a little off, or if you can't use
data-content
this way. 我不确定我的语法是否还差一点,或者您是否不能以这种方式使用
data-content
。
Is it possible to specify a function for a Popover's content using the data-content
attribute? 是否可以使用
data-content
属性为Popover的内容指定功能? Or am I misunderstanding the docs? 还是我误会了文档?
Pass the data-
, (ie, data-content) attribute through $(elem).popover(options)
通过
$(elem).popover(options)
传递data-
(即data-content)属性
$('[data-toggle="popover"]').popover({
content: my_function(this)
})
Here's your revised fiddle for you to review. 这是您修改过的小提琴,供您查看。 https://jsfiddle.net/heb6gt6p/1/
https://jsfiddle.net/heb6gt6p/1/
无法使用data-content
属性为Popover的内容指定功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.