Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.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 创建的DIV中的链接导致在悬停时删除DIV_Javascript_Jquery_Html_Append_Mouseout - Fatal编程技术网

Javascript 创建的DIV中的链接导致在悬停时删除DIV

Javascript 创建的DIV中的链接导致在悬停时删除DIV,javascript,jquery,html,append,mouseout,Javascript,Jquery,Html,Append,Mouseout,这是我的密码: var tagDes = document.createElement('DIV'); tagDes.className = 'tagDes'; tagDes.style.cssText = 'position:absolute;'+ 'background:#282828;'+

这是我的密码:

var tagDes = document.createElement('DIV');
                    tagDes.className = 'tagDes';
                    tagDes.style.cssText = 'position:absolute;'+
                                    'background:#282828;'+
                                    'color:#fff;'+
                                    'padding:10px;'+
                                    'top:'+(posX+hei)+'px;'+
                                    'left:'+(posY+wid)+'px;'+
                                    'font-size:10pt;';
                    tagDes.onmouseout = function(){
                                        $(this).remove();
                                    };
                    $('#main-container').append(tagDes);
                    $('.tagDes').append(array[5]+'<a class="tagMenu">sdsdssds</a>');
var tagDes=document.createElement('DIV');
tagDes.className='tagDes';
tagDes.style.cssText='位置:绝对;'+
'背景:#282828;'+
'颜色:#fff;'+
'填充:10px;'+
'顶部:'+(posX+hei)+'px;'+
'左:'+(posY+wid)+'px;'+
'字体大小:10pt;';
tagDes.onmouseout=函数(){
$(this.remove();
};
$(“#主容器”).append(tagDes);
$('.tagDes').append(数组[5]+'sdssds');
posX、posY、hei、wid正在参照用于定位的元素。数组[5]是一个字符串。
我想悬停一个
li
并创建一个div,其中包含链接(
tagMenu
class)(看起来像
title
属性)。但当我将链接悬停在该div内时,该div将
remove()
。我要寻找的是,当我将链接悬停时,div仍然可见,当我从中移出鼠标时,div将从页面中删除。有什么建议吗?请帮助我。

如果我正确理解了您的意思,您希望将
onmouseout
事件绑定到内部链接元素。然后代码可以是这样的(我使用了更多jQuery来简化它):

var$tagDes=$('').css({
背景:"282828",,
颜色:“#fff”,
填充:“10px”,
顶部:(posX+hei)+“px”,
左:(posY+wid)+“px”,
字体大小:“10磅”
})
.append(数组[5]+'sdssds')
.appendTo(“#主容器”);
$tagDes.on('mouseleave',function(){
$tagDes.remove();
});

尝试以下方法:

 tagDes.onmouseout = function(e){
 if (e.toElement.parentNode == this || e.toElement == this) {
       return;
     }
   $(this).remove();
   };

posX和posY是否颠倒了方向?不,它给出了正确的值。它将返回
li
的位置,以便div可以靠近itI的旁边,意思是:
'top:'+(posX+hei)+'px;'
使用水平位置和高度,并且
左:'+(posY+wid)+'px;'使用垂直位置和宽度。那么posX和posY是不是走错了方向?哇…离我的交易太近了。但是现在,div不是mouseout pal上的
remove
onmouseout。它将在linkmouseout上被删除。你想在div mouseout上删除它吗?是的,但它非常接近我的要求。我会投票支持你的,朋友。哦,我明白了,所以你需要
mouseleave
事件,而不是
mouseout
。请参阅更新的代码。无论如何,很高兴你找到了一个适合你的解决方案!
 tagDes.onmouseout = function(e){
 if (e.toElement.parentNode == this || e.toElement == this) {
       return;
     }
   $(this).remove();
   };