美文网首页
鼠标移入移出,获取当前元素

鼠标移入移出,获取当前元素

作者: 装在壳子里的刺猬 | 来源:发表于2019-09-16 09:09 被阅读0次
<style>
p{
    display: inline-block;
    width: 5rem;
    margin-bottom: 15px;
    margin-right: 10px;
    height: 1.875rem;
    text-align: center;
    line-height: 1.875rem;
    background: rgba(248,248,248,1);
    border: 1px solid rgba(221,221,221,1);
    font-size: 12px;
    font-family: MicrosoftYaHei;
    position: relative;
    color: rgba(51,51,51,1);
}
p img{
    width: 1rem;
    height: 1rem;
    position: absolute;
    top: -0.5rem;
    right: -0.5rem;
    display: none;
}
</style>
<body>
<p class="msg">
    市场化
    <img src="../img/close2.png" alt="">
</p>
<p class="msg">
    权益类
    <img src="../img/close2.png" alt="">
</p>
<script>
//鼠标移入移出
//第一种方法
    $(function(){
        $(msg).on({
            mouseover : function(){
                $(this).find('img').show();
          } ,
          mouseout : function(){
              $(this).find('img').hide();
          } 
        }) ;
    }) ; 
//第二种方法
    $(function(){
        $(msg).hover({
            function(){
                $(this).find('img').show();
          } ,
            function(){
                $(this).find('img').hide();
          } 
        }) ;
    }) ; 
//删除当前标签
    $(function(){
        $(this).parent().hide()
    })
</script>
</body>

鼠标移入,切换当前标签

$(this).wrap('<h1>')

标签切换回来

$(this).unwrap()

相关文章

网友评论

      本文标题:鼠标移入移出,获取当前元素

      本文链接:https://www.haomeiwen.com/subject/tdrbyctx.html