开发者社区 问答 正文

如何用jQuery对HTML元素事件进行附加?

如何用jQuery对HTML元素事件进行附加?

展开
收起
真的很搞笑 2021-11-07 13:45:42 447 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • 下面通过2个例子来说明

    例子1,选择所有的button元素,在其click事件中,对所有p元素进行toggle。

    $("button").click(function(){ $("p").toggle(); }); 例子2,选择ID为p1的元素,在mouseenter事件中,进行alert。

    $("#p1").mouseenter(function(){ alert("You entered p1!"); });

    2021-11-09 11:19:18 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论