js控制div显示与隐藏,js利用"hover"属性

2025-03-09 22:11:28
推荐回答(5个)
回答1:

1.先要将B隐藏,添加idB面内容

2.添加方法A面内容

3.js:function fn(){
         var divb = document.getElementById("divb");
         var diva = document.getElementById("diva");
         diva.style.display="none";
         divb.style.display="block";
    }
同理可以设置鼠标移除 B隐藏,A显示

回答2:

上面2位的代码,我都试了一下,发现


jquery那位写的会不停的闪烁

原生写的不太好循环复用


你看看我这个满足你需求吗?



  •  

  •  
  • 回答3:

    $(function(){
            $('li div.a').hover(
                function(){
                    $(this).hide();
                    $(this).next().show();
                },
                function(){
                    $(this).show();
                    $(this).next().hide();
                }
            )
        })

    回答4:

    $(function () {
        function toggleFn() {
            $(this).find('div').toggle();
        };
        $('li').hover(toggleFn, toggleFn);
    });

    回答5:

    $('.a').mouseenter(function() {
    this.style.display = 'none';
    this.nextElementSibling.style.display = 'block';
    });
    $('.a').mouseout(function() {
    this.style.display = 'block';
    this.nextElementSibling.style.display = 'none';
    });

    相关问答
    最新问答