当我以编程方式调用它时如何将参数传递给模态? [英] How to pass parameters to modal when i call it programmatically?

查看:68
本文介绍了当我以编程方式调用它时如何将参数传递给模态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我像这样以编程方式调用引导模式

I call bootstrap modal programmatically like this

$('#confirmModal').modal()

但是当我这样做时,事件"发生在:

But when i do so, "event" in:

$('#confirmModal').on('show.bs.modal', function (event) {
   var button = $(event.relatedTarget); 
})

没有relatedTarget",但我需要它.如何使用 $('#confirmModal').modal()

doesn't have "relatedTarget" but i need it. How to pass it using $('#confirmModal').modal()

推荐答案

relatedTarget 不能设置,它是事件的只读属性.show.bs.modal BTW 是由引导模式本身触发的,所以无论哪种方式你都会迷路.

You cannot set relatedTarget, it is a readonly property of the event. show.bs.modal is BTW fired by the bootstrap modal itself, so either way you are lost.

但是为什么不以编程方式触发模态触发按钮的click事件,它与调用modal()完全相同,然后 relatedTarget 存在:

But why not trigger the click event of the modal trigger button programmtically, it would be the exact same as calling modal(), and then the relatedTarget is present :

$("#button").click();

假设你已经形成了这样的模态触发按钮":

Under the assumption that you have well formed "modal trigger button" like this :

<button id="button" data-toggle="modal" data-target="#confirmModal">show modal</button>

看这里 -> http://jsfiddle.net/y3s1t7ea/

see here -> http://jsfiddle.net/y3s1t7ea/

这篇关于当我以编程方式调用它时如何将参数传递给模态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆