jQuery -笔记 事件注册

jQuery 事件注册

  1. jQuery单个事件注册,
  2. on() 可绑定一个或多个事件
  3. on() 的注册事的 优势
div{width:100px;height:100px;background-color:#8A2BE2;}.curr{background-color:#D2691E;}
  <div></div>

jQuery -代码

  //jQuery  事件注册
  // 1、单个事件注册
  $("div").mouseover(function() {

      $(this).css("width", 300)

  });

  $("div").mouseout(function() {

      $(this).css("width", 100)

  });

  //2、事件处理  on() 可绑定一个或多个事件
  $("div").on({

      mouseover: function() {

          $(this).css("width", 300)

      },

      mouseout: function() {

          $(this).css("width", 100)

      },

      click: function() {

          $(this).css("width", 500)

      }

  });

  $("div").on("mouseenter mouseleave", function() {

      $(this).toggleClass("curr")

  })


  // 事件委托
  $("ul").on("click", "li", function() { //click 是绑定在ul身上,但触发的对像是li
      alert(11)

  })


  //可以给动态创建的元素绑定事件
  var di = $("<div>我是新建的</div>");

  $("div").append(di)

   $("div").on("mouseover", "div", function() {

      alert(12522)

  })
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值