[英]how can i call modal on bootstrap via javascript/jquery function
I was having a problem on calling bootstrap modal on a simple button or link maybe because its having a conflict with my select2 plugin (which I'm not really sure of) ,by the way I did just append the button to the select2 drop down, here is my javascript that wont work: 我在一个简单的按钮或链接上调用bootstrap模式时遇到问题可能是因为它与我的select2插件(我不太确定)有冲突,顺便说一下我只是将按钮附加到select2下拉列表,这是我的JavaScript无法工作:
$(".select2-drop").append('<table><tr><td><button class="btn" data-toggle="modal" data-target="#ModalAdd">New Supplier</button></td></tr></table>');`
because of this I'm just trying to do a javascript/jquery function to open the modal ( dont know if its the best way.) 因为这个我只是想做一个javascript / jquery函数来打开模态(不知道它是否是最好的方式。)
here is my javascript code: 这是我的javascript代码:
$(".select2-drop").append('<table><tr><td><button class="btn" onClick="modal() ">New Supplier</button></td></tr></table>');
tried to alert some message on it and it worked: 试图提醒一些消息并且它有效:
function modal(){
alert("pressed");
}
My question is, How can I call modal on bootstrap via javascript/jquery function? 我的问题是,如何通过javascript / jquery函数调用bootstrap上的模态?
any kind of help/suggestions would really be appreciated, Thank you and have a good Day! 任何形式的帮助/建议真的很感激,谢谢你,祝你有个美好的一天!
Try this 尝试这个
$('#modalID').modal('show')
By HTML 通过HTML
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#yourmodalid">
Launch modal
</button>
If you want it completely "mechanical" see this example : 如果你想完全“机械”,请看这个例子:
fiddle -> http://jsfiddle.net/RvJV8/ 小提琴 - > http://jsfiddle.net/RvJV8/
$("#btnOpen").click(function() {
$("#myModal").modal();
});
Did you ever tried this? 你有没有试过这个? It works ..
有用 ..
$(".select2-drop").append('<table><tr><td><button class="btn" onclick="$("#myModal").modal();">New Supplier</button></td></tr></table>');
forked fiddle -> http://jsfiddle.net/3uZAZ/ 分叉小提琴 - > http://jsfiddle.net/3uZAZ/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.