Javascript jQuery/Bootstrap:子DIV打开父模式
所以我有嵌套的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
$(“#父项”)。单击(函数(){
$('.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();//做其他事)
帮助你?很遗憾,我没有发现这正是我需要的,但我会接受你的回答谢谢!我没有。我当时不能做,但现在我会再等一段时间。我发现这正是我需要的,但我会接受你的回答谢谢!我没有。我当时不能做,但现在我会再等一段时间。