首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何找到bootstrap模式对话的源代码

如何找到bootstrap模式对话的源代码
EN

Stack Overflow用户
提问于 2011-12-12 23:41:07
回答 1查看 9.1K关注 0票数 4

我使用的是twitter、bootstrap modal和jquery。

当有多个按钮可以创建模式对话框时,如何找到源按钮?

在使用bootstrap-modal之前,我使用onclick来显示确认消息,例如,onclick="newGame(3,true)";现在我想使用bootstrap-modal来执行此操作。

html,

代码语言:javascript
复制
<button type="button" class="btn" id="ctrl6" data-controls-modal="my-modal" data- 
backdrop="static">3</button>
<button type="button" class="btn" id="ctrl7" data-controls-modal="my-modal" data-
backdrop="static">4</button>
<button type="button" class="btn" id="ctrl8" data-controls-modal="my-modal" data- 
backdrop="static">5</button>

<div id="my-modal" class="modal hide fade in" style="display: none;">
...
</div>

js

代码语言:javascript
复制
  $(document).ready(function() {
      // Hide modal if "Go back" is pressed
      $('#my-modal .go-back-button').click(function() {
        $('#my-modal').modal('hide');
      });

      // Hide modal if "Okay" is pressed
      $('#my-modal .okay-button').click(function() {
        $('#my-modal').modal('hide');
      });
  });

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2011-12-12 23:46:55

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

代码语言:javascript
复制
$('#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
});

示例here (jsfiddle)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8476842

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档