Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.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 jQuery/Bootstrap:子DIV打开父模式_Javascript_Jquery_Html_Css_Twitter Bootstrap - Fatal编程技术网

Javascript jQuery/Bootstrap:子DIV打开父模式

Javascript jQuery/Bootstrap:子DIV打开父模式,javascript,jquery,html,css,twitter-bootstrap,Javascript,Jquery,Html,Css,Twitter Bootstrap,所以我有嵌套的div,一个简单的版本如下所示: $(“#父项”)。单击(函数(){ $('.parent').modal('show'); }); $(“#子项”)。单击(函数(){ $('.parent').modal('hide');//添加到try和hide $('.child').modal('show'); $('.parent').modal('hide');//添加到try和hide }); 之所以会发生这种情况,是因为您的孩子的点击事件正在向家长涌来。对子div使用e.stop

所以我有嵌套的div,一个简单的版本如下所示:

$(“#父项”)。单击(函数(){
$('.parent').modal('show');
});
$(“#子项”)。单击(函数(){
$('.parent').modal('hide');//添加到try和hide
$('.child').modal('show');
$('.parent').modal('hide');//添加到try和hide
});

之所以会发生这种情况,是因为您的孩子的点击事件正在向家长涌来。对子div使用
e.stopPropogation()
。这将防止单击事件传播到父级

$(“#父项”)。单击(函数(){
$('.parent').modal('show');
});
$(“#子项”)。单击(函数(e){
e、 停止传播();
$('.parent').modal('hide');//添加到try和hide
$('.child').modal('show');
$('.parent').modal('hide');//添加到try和hide
});

之所以会发生这种情况,是因为您的孩子的点击事件正在向家长涌来。对子div使用
e.stopPropogation()
。这将防止单击事件传播到父级

$(“#父项”)。单击(函数(){
$('.parent').modal('show');
});
$(“#子项”)。单击(函数(e){
e、 停止传播();
$('.parent').modal('hide');//添加到try和hide
$('.child').modal('show');
$('.parent').modal('hide');//添加到try和hide
});

通过在下面的属性中提及目标,您可以轻松处理此类情况

$('#parent, #child').click(function() {
   var target = $(this).data('target');
   $('.'+target).modal('show');
   // write code to hide others if necessary
});

通过在下面的属性中提及目标,您可以轻松处理此类情况

$('#parent, #child').click(function() {
   var target = $(this).data('target');
   $('.'+target).modal('show');
   // write code to hide others if necessary
});

在显示模式之前,请尝试以下操作:

 $( '.modal' ).remove();
$( '.child' ).modal('show');

在使用show之前,请删除该模式。希望这将解决您的问题

在显示模式之前尝试以下操作:

 $( '.modal' ).remove();
$( '.child' ).modal('show');

在使用show之前,请删除该模式。希望这能解决您的问题

e.preventDefault()
$('#child')。单击(函数(e){e.preventDefault();//做其他事);
对您有帮助?不幸的是,没有noDoes e.preventDefault()
$('#child')。单击(函数(e){e.preventDefault();//做其他事)
帮助你?很遗憾,我没有发现这正是我需要的,但我会接受你的回答谢谢!我没有。我当时不能做,但现在我会再等一段时间。我发现这正是我需要的,但我会接受你的回答谢谢!我没有。我当时不能做,但现在我会再等一段时间。