使用javascript onClick显示引导模式
Display Bootstrap Modal using javascript onClick
我需要能够使用onClick=""
或类似功能打开Twitter引导模式窗口。只需要代码就可以进入onClick=""
。我正在尝试制作一个可点击的div
来打开模态。
代码摘录:
分区代码:
<div class="span4 proj-div" onClick="open('GSCCModal');">
模态分区代码:
<div id="GSCCModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
Javascript:
function open(x){
$(x).modal('show');
}
您不需要onclick。假设您使用的是引导3引导3文档
<div class="span4 proj-div" data-toggle="modal" data-target="#GSCCModal">Clickable content, graphics, whatever</div>
<div id="GSCCModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
如果您使用的是Bootstrap 2,请按照此处的标记进行操作:http://getbootstrap.com/2.3.2/javascript.html#modals
我正在寻找onClick选项,以根据列表中的项目设置模态的标题和正文。T145的答案帮助很大,所以我想分享我是如何使用它的。
确保包含JavaScript函数的标签是text/JavaScript类型,以避免冲突:
<script type="text/javascript"> function showMyModalSetTitle(myTitle, myBodyHtml) {
/*
* '#myModayTitle' and '#myModalBody' refer to the 'id' of the HTML tags in
* the modal HTML code that hold the title and body respectively. These id's
* can be named anything, just make sure they are added as necessary.
*
*/
$('#myModalTitle').html(myTitle);
$('#myModalBody').html(myBodyHtml);
$('#myModal').modal('show');
}</script>
这个函数现在可以在onClick方法中从按钮等元素内部调用:
<button type="button" onClick="javascript:showMyModalSetTitle('Some Title', 'Some body txt')"> Click Me! </button>
必须首先创建一个JavaScript函数,该函数包含您想要执行的操作:
function print() { console.log("Hello World!") }
然后必须在onClick方法中从元素内部调用该函数:
<a onClick="print()"> ... </a>
您可以直接从Bootstrap 3文档中了解更多关于模态交互的信息,如下所示:http://getbootstrap.com/javascript/#modals
您的模态绑定也不正确。它应该是这样的,其中"myModal"=元素的ID:
$('#myModal').modal(options)
换句话说,如果你真的想保留你已经拥有的,在GSCCModal前面加一个"#",看看这是否有效。
将onClick绑定到div元素也不是很明智;像按钮这样的东西会更合适。
希望这能有所帮助!
我也遇到了同样的问题,经过大量的研究,我终于构建了一个js函数来根据我的需求动态创建模式。使用此功能,您可以在一行中创建弹出窗口,例如:
puyModal({title:'Test Title',heading:'Heading',message:'This is sample message.'})
或者,您可以使用其他复杂的功能,如iframe、视频弹出窗口等。
在上查找https://github.com/aybhalala/puymodals有关演示,请访问http://pateladitya.com/puymodals/
- 缩略图单击时图像未以模式显示
- 模式显示文本区域内容不是字符串
- 在ajax回调(safari)中调用bootstrap模式显示
- Twtitter Bootstrap模式显示事件多次触发
- 以引导模式显示表单结果
- 引导模式显示,但没有可见文本
- 无法在提交时获取引导模式显示
- 提交表单后,将引导模式显示为“谢谢”
- 使用reactjs、localStorage和state(遍历)以模式显示表中的数据
- XPages-以读取模式显示附件
- JavaScript在验证后切换模式显示
- Jquery Cookie通过模式显示/隐藏菜单
- Rails Rendering从索引页以Bootstrap模式显示
- 强制网站仅以横向模式显示
- 如何使用单一模式显示多个图像
- 链接JavaScript不工作时,Bootstrap模式显示
- 引导模式显示不会移除隐藏属性
- Google Maps API v3 + Foundation 4 Reveal模式显示不正常
- 引导模式显示和隐藏在操作中
- 将JqGrid列模式显示为日期,超链接显示NAN/NAN/NAN