Javascript 将鼠标停留在元素onclick上
这可能看起来很简单,但不幸的是,我不知道如何获得这种效果 我有一个div,里面有一个子div,需要在父div的Javascript 将鼠标停留在元素onclick上,javascript,jquery,html,css,Javascript,Jquery,Html,Css,这可能看起来很简单,但不幸的是,我不知道如何获得这种效果 我有一个div,里面有一个子div,需要在父div的鼠标上方显示 子div中有另一个内容面板,必须在单击子div时显示 这2个功能很好,但这里的问题是,只有在单击child时,我才需要在鼠标左键上显示child div $(".wrapper").mouseover(function() { $(this).find('.child').show(); }).mouseleave(function(){
鼠标上方显示
子div中有另一个内容面板,必须在单击子div时显示
这2个功能很好,但这里的问题是,只有在单击child时,我才需要在鼠标左键上显示child div
$(".wrapper").mouseover(function() {
$(this).find('.child').show();
}).mouseleave(function(){
$(this).find('.child').hide();
});
$(".child").click(function() {
$(this).find('span').show();
});
单击时在父级上添加一个类,检查鼠标左键上是否有该类:
$(".wrapper").mouseover(function() {
$(this).find('.child').show();
}).mouseleave(function(){
if(!$(this).hasClass('clicked'))
$(this).find('.child').hide();
});
$(".child").click(function() {
$(this).parent().addClass('clicked').find('.child span').show();
});
我想这会对你有帮助
试试这个:
$(".wrapper").mouseover(function() {
$(this).find('.child').show();
}).mouseleave(function(){
if($(this).find('.child span').is(':visible') == false){
$(this).find('.child').hide();
}
});
$(".child").click(function() {
$(this).find('span').show();
});
试试这个:
var clicked=false;
$(".wrapper").mouseover(function() {
$(this).find('.child').show();
}).mouseleave(function(){
if(!clicked){
$(this).find('.child').hide();
}
});
$(".child").click(function() {
$(this).find('span').show();
clicked=true;
});
你的意思是“我需要在鼠标左键上隐藏子div”吗?不是。它在鼠标左键上隐藏它,但我想在鼠标左键上显示它,仅当该子键处于cliked@Sowmya:表示如果单击了子对象,则div不会在鼠标离开时隐藏?