Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在引导中检测单击show的button类_Javascript_Jquery_Css_Twitter Bootstrap - Fatal编程技术网

Javascript 如何在引导中检测单击show的button类

Javascript 如何在引导中检测单击show的button类,javascript,jquery,css,twitter-bootstrap,Javascript,Jquery,Css,Twitter Bootstrap,我有以下元素 <button type="button" class='launch' data-toggle="modal" data-target="#myModal">Launch modal</button> <button type="button" class='boom' data-toggle="modal" data-target="#myModal"> Boom </button> 如何检查按钮在函数中是否有类启动或动臂? 或

我有以下元素

<button type="button" class='launch' data-toggle="modal" data-target="#myModal">Launch modal</button>
<button type="button" class='boom' data-toggle="modal" data-target="#myModal"> Boom </button>
如何检查按钮在函数中是否有类启动或动臂? 或者换句话说,问题是如何在该函数中获取触发此操作的按钮。

使用jQuery方法检查该类是否存在

$('#element').hasClass('launch'); // returns true or false;
请尝试下面的代码。请将
.myModalbtn
类添加到两个按钮

$('.myModalbtn').on('hidden', function () {   

       $(this).hasClass('launch')) // if the it has launch class -> returns true else false;
});

您可以为每个按钮添加单独的类,例如
.modalBtn
,并执行以下操作:

$('.modalBtn').click(function() {
if ($(this).hasClass('launch')) showModal($('.launch'));
else if ($(this).hasClass('boom')) showModal($('.boom'));
});

function showModal( $btn ) {


//insert code to show modal (you can find it in the bootstrap javascript docs. Now you have $btn object to use.



}

但是我无法访问myModal中的按钮。我不知道如何获取按钮,我需要获取触发此模式的按钮以显示。这取决于您要检查的按钮。最好使用onclick并将其绑定到按钮上..如下面的答案所示,使用jquery的.hasClass()方法你的意思是什么取决于要检查的按钮?为什么不收听
单击
事件?我认为不可能在
显示
事件中获取触发器按钮
$('.modalBtn').click(function() {
if ($(this).hasClass('launch')) showModal($('.launch'));
else if ($(this).hasClass('boom')) showModal($('.boom'));
});

function showModal( $btn ) {


//insert code to show modal (you can find it in the bootstrap javascript docs. Now you have $btn object to use.



}