midnighteen 2015-10-15 01:35 采纳率: 0%
浏览 1298

jquery toggle使用的疑问

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="../jquery-1.8.3.js"></script>
<script>
$(function(){
    $("div").hover(
        function(){$(this).addClass("over");},
        function(){$(this).removeClass("over")}
    );
    $("div>p").toggle(
        function(){
            $(this).next().toggle(function(){alert("a");},function(){alert("b");});
            },
        function(){
            $(this).next().toggle(function(){alert("c");},function(){alert("d");});
            }
        );
});
</script>
<style>
div p{
    color:green;
}
.over{
    background-color:#C9F;
}
img{
    width:10px;
    height:10px;
}
div.h{
    display:none;
}
div.h1{
    display:block;
}

</style>
</head>

<body>
<div><p><img src="1.jpg"/>1</p><div class="h">AAAAAA</div></div>
<div><p><img src="1.jpg"/>2</p><div class="h">BBBBBB</div></div>
<div><p><img src="1.jpg"/>3</p><div class="h">CCCCCC</div></div>
<div><input type="button" onclick="show()"/></div>
</body>
</html>

为什么我点击标签的时候没有弹出a,b,c,d

  • 写回答

3条回答 默认 最新

  • Go 旅城通票 2015-10-15 09:20
    关注

    你只是给p的兄弟节点div注册了点击事件,div隐藏你有点击不到。。当然没反应了

             $(function () {
                $("div").hover(
                    function () { $(this).addClass("over"); },
                    function () { $(this).removeClass("over") }
                );
                $("div>p").toggle(
                    function () {
                        $(this).next().toggle();////////
                    },
                    function () {
                        $(this).next().toggle();////////
                    }
                    );
            });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值