<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://apps.bdimg.com/libs/jquery/1.7.0/jquery.js">
</script>
<script>
$(document).ready(function(){
  $("#div1").on("click",function(){
    $(this).css("background-color","pink");
  });
  $("#div2").live("click",function(){
    $(this).css("background-color","pink");
  });
});
</script>
</head>
<body>

<h4 style="color:green;">该实例演示了如何使用 on() 和 live()。</h4>

<div >这是一些文本。
<p>点击此处,使用 <b>on() 方法来设置背景颜色</b>。</p>
</div><br>

<div >这是一些文本。
<p>点击此处,使用 <b>live() 方法来设置背景颜色</b>。</p>
</div>
<p><b>注意:</b>  live() 方法在 jQuery 版本 1.7 中被废弃,在版本 1.9 中被移除。请使用 on() 方法代替</p>
</body>
</html>

  http://www.runoob.com/jquery/event-on.html

http://api.jquery.com/on/

jQuery on() 和 live

jQuery on() 和 live

 

相关文章:

  • 2021-06-29
  • 2021-07-05
  • 2021-06-11
  • 2022-12-23
猜你喜欢
  • 2021-10-09
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2021-07-26
  • 2022-12-23
相关资源
相似解决方案