Jquery 如何查找引导模式对话框的源

Jquery 如何查找引导模式对话框的源,jquery,twitter-bootstrap,Jquery,Twitter Bootstrap,我正在使用twitter引导模式和jquery 当有多个按钮可用于创建模式对话框时,如何查找源按钮 在引导模式之前,我使用onclick来显示确认消息,比如onclick=“newGame(3,true)”;现在我想用引导模式来实现它 html 谢谢。该函数接受一个参数,该参数链接到触发事件的元素: $('#my-modal .okay-button').click(function(e) { // e is the element that triggered the event

我正在使用twitter引导模式和jquery

当有多个按钮可用于创建模式对话框时,如何查找源按钮

在引导模式之前,我使用onclick来显示确认消息,比如onclick=“newGame(3,true)”;现在我想用引导模式来实现它

html

谢谢。

该函数接受一个参数,该参数链接到触发事件的元素:

$('#my-modal .okay-button').click(function(e) {
   // e is the element that triggered the event
   console.log(e.target); // outputs an Object that you can then explore with Firebug/developer tool.
   // for example e.target.firstChild.wholeText returns the text of the button
});

示例(JSFIDLE)。

您可能会发现最近的拉取请求很有用:

此提交修改了模式插件,以便它获取触发元素上的所有数据属性。通过在所有触发元素中添加唯一标识符,比如说
data user=“some_uid”
,将来可以从模态对象检索数据

例如,如果使用示例中的按钮:

<button data-user="4" ... >
<button data-user="5" ... >
<button data-user="6" ... >

注意:我意识到,自从提出这个问题以来,模式的API发生了重大变化,这也是我忽略按钮标记的其他细节的部分原因。但是,我认为需要解决的问题仍然是相关的。

这里的“e”是来自ok/cancel锚元素的事件。可能是我的问题不清楚。我试图找出是从哪个按钮(ctrl6、ctrl7等)创建的模态对话框。我想在modal ok/cancel@vi.su中查看这些详细信息<代码>e是按钮的直接“链接”。看到这个例子,谢谢你的回复。我无法找到此问题的解决方案,因此我现在将所有“ctrlxx”按钮移动到模式,在页面中只留下一个按钮。:-)
$('#my-modal .okay-button').click(function(e) {
   // e is the element that triggered the event
   console.log(e.target); // outputs an Object that you can then explore with Firebug/developer tool.
   // for example e.target.firstChild.wholeText returns the text of the button
});
<button data-user="4" ... >
<button data-user="5" ... >
<button data-user="6" ... >
// Hide modal if "Okay" is pressed
$('#my-modal').on('click', '.okay-button', function(e) {
  var modal = $(e.delegateTarget).data('modal');

  console.log('Originating element user: ' + modal.options.user);

  modal.hide();
});