Javascript 关闭按钮在jQuery内部div中不起作用
我有一个名为datahover的Div,我将jquery放在其中,这样如果我在该Div内单击,它就不会隐藏,但当我在该Div外单击时,它就会隐藏。但是问题是关闭按钮在那个div里面,所以当我点击这个关闭按钮时,div并没有隐藏 这里的关闭按钮是一个标签,里面有一个标签 HTML代码:Javascript 关闭按钮在jQuery内部div中不起作用,javascript,jquery,html,css,jquery-selectors,Javascript,Jquery,Html,Css,Jquery Selectors,我有一个名为datahover的Div,我将jquery放在其中,这样如果我在该Div内单击,它就不会隐藏,但当我在该Div外单击时,它就会隐藏。但是问题是关闭按钮在那个div里面,所以当我点击这个关闭按钮时,div并没有隐藏 这里的关闭按钮是一个标签,里面有一个标签 HTML代码: <div class="datahover"> <a href="javascrip
<div class="datahover">
<a href="javascript:void(0);"><i class="fa fa-times" aria-hidden="true"></i></a>
<div class="facultydata">
<div class="leftside">
<img src="deepak.jpg">
<h3>Deepak Chaudhary</h3>
</div>
<div class="table-responsive";
<table class="table">
<tbody>
<tr>
<th>Designation</td>
<td>ME</td>
</tr>
<tr>
<th>Qualification</td>
<td>CE</td>
</tr>
<tr>
<th>Teaching Experience</td>
<td>8 Years</td>
</tr>
<tr>
<th>Industry Experience</td>
<td>7 Years</td>
</tr>
<tr>
<th>Department</td>
<td>Computer</td>
</tr>
<tr>
<th>Area</td>
<td>All</td>
</tr>
<tr>
<th>Email</td>
<td>dac81048@gmail.com</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
想法是在关闭按钮上使用单击事件的
stopPropagation
,如:
$('.fa-times').click(function(event) {
event.stopPropagation();
$(".datahover").hide()
});
当您使用mouseup
并检查e.target
时,此处也不需要事件传播
下面给出的代码片段:
/**datahover在单击外部时隐藏**/
$(文档).mouseup(函数(e){
var容器=$(“.datahover”);
如果(!container.is(e.target)&&container.has(e.target).length==0){
container.css({
“显示”:“无”
});
$('.facultysection').css({
“背景”:“fff”
});
如果($(窗口).width()>767){
$('html,body').css({
“溢出-x”:“隐藏”,
“溢出-y”:“自动”
});
}否则{
$('html,body').css({
“溢出-x”:“隐藏”,
“溢出-y”:“自动”
});
}
}
});
$('.fa times')。单击(函数(事件){
event.stopPropagation();
$(“.datahover”).hide()
});代码>
迪帕克·乔杜里
任命
我
资格
总工程师
教学经验
8年
行业经验
7年
部门
电脑类
地区
全部的
电子邮件
dac81048@gmail.com
在关闭按钮上使用单击事件的停止播放
,如:
$('.fa-times').click(function(event) {
event.stopPropagation();
$(".datahover").hide()
});
当您使用mouseup
并检查e.target
时,此处也不需要事件传播
下面给出的代码片段:
/**datahover在单击外部时隐藏**/
$(文档).mouseup(函数(e){
var容器=$(“.datahover”);
如果(!container.is(e.target)&&container.has(e.target).length==0){
container.css({
“显示”:“无”
});
$('.facultysection').css({
“背景”:“fff”
});
如果($(窗口).width()>767){
$('html,body').css({
“溢出-x”:“隐藏”,
“溢出-y”:“自动”
});
}否则{
$('html,body').css({
“溢出-x”:“隐藏”,
“溢出-y”:“自动”
});
}
}
});
$('.fa times')。单击(函数(事件){
event.stopPropagation();
$(“.datahover”).hide()
});代码>
迪帕克·乔杜里
任命
我
资格
总工程师
教学经验
8年
行业经验
7年
部门
电脑类
地区
全部的
电子邮件
dac81048@gmail.com
这是什么:为什么不运行一个检查,看看目标是否是$('.datahover>a>i.fa.fa times')
?您不需要向按钮添加事件来单击并隐藏div$(“.fa times”)。在(“单击”,函数(){$(“.datahover”).hide(););是Table的引导类这是什么:为什么不运行一个检查,看看目标是否是$('.datahover>a>i.fa.fa times')
?您不需要向按钮添加事件来单击和隐藏div$(“.fa times”)。在(“单击”,函数(){$(.datahover”).hide();});是TableThank的bootstrap类谢谢…它工作得很好。谢谢…它工作得很好。