前端鲨鱼 2022-04-07 20:53 采纳率: 90%
浏览 30
已结题

jQuery on绑定事件 报错解决

在学习绑定多个事件时 出现报错

img


附上源代码 希望可以得到解决

        <script>
        $(function(){
            // $("div").on("click",function(){
            //     $(this).css("background","red")
            // })
            $("div").on({
                click:functon(){
                    $(this).css("background","red");
                },
                mouseenter:function(){
                    $(this).css("background","blue")
                },
                mouseleave:function(){
                    $(this).css("background","yellow")
                }
            })
        });
        </script>

  • 写回答

2条回答 默认 最新

  • 你好!机器人 2022-04-07 22:22
    关注

    click那里是function,你打错了

    
            <script>
            $(function(){
                // $("div").on("click",function(){
                //     $(this).css("background","red")
                // })
                $("div").on({
                    click:function(){
                        $(this).css("background","red");
                    },
                    mouseenter:function(){
                        $(this).css("background","blue")
                    },
                    mouseleave:function(){
                        $(this).css("background","yellow")
                    }
                })
            });
            </script>
     
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月15日
  • 已采纳回答 4月7日
  • 创建了问题 4月7日