在引导程序弹出窗口中使用交互式元素

Kal*_*ist 18 jquery popover twitter-bootstrap

我在链接点击上成功使用了bootstrap popover.我在popover中有一些表单元素:textfield,checkbox和button.我能够使用jquery.live()附加一个按钮监听器,但在该按钮监听器中,我似乎没有任何正确的表单元素的访问权限.如果我在控制台日志中跟踪它们,它们就存在,但它们的值始终保持原始默认值,所以如果我去$('#txtComment').val(); 无论我放入字段中,字符串总是相同的.

是否有任何示例,教程或源代码我可以看一下在引导程序弹出窗口中使用任何类型的交互性的东西?

这就是我设置popover的方式:

this.commentLink.popover({
  trigger: 'manual',
  placement: 'right',
  html : true,
  content: function () {
    return $('#commentPopout').html();
  }
}).popover('hide');

//jquery.on won't work here so we use live
$('#btnSubmitComment').live('click', this.proxy(this.commentSubmitClick));
Run Code Online (Sandbox Code Playgroud)

然后我这样做是为了成功展示它:

this.commentLink.popover('show');
Run Code Online (Sandbox Code Playgroud)

这是按钮点击功能:

commentSubmitClick: function(e){
  console.log($('#txtComment').val());//always shows default text regardless of what I've actually typed in the field
}
Run Code Online (Sandbox Code Playgroud)

Alp*_*Alp 19

语法改变了.Kalin C Ringkvist的答案需要稍加修改:

var popover = this.commentLink.data('popover').tip();
Run Code Online (Sandbox Code Playgroud)

注意方法tip()而不是$tip.

  • 从Bootstrap 3.0开始,语法为`this.commentLink.data("bs.popover").$ tip` (3认同)

Kal*_*ist 15

好极了!弄清楚了.为什么,为什么没有记录?我想念在actionscript中工作.

var popover = this.commentLink.data('popover').$tip;
var comment = popover.find('#txtComment').val();//gives correct string
Run Code Online (Sandbox Code Playgroud)

当弹出窗口实际可见时,必须运行此代码,因为元素在不可见时不存在.

-Oh,并且不推荐使用jquery.live(),但是一旦创建了popover,你就可以使用这个$ tip变量来获取按钮引用.