Jquery学习笔记

事件:

1.live()事件:

  可以向一个网页中不存在的元素添加事件,存在的也可以

例子:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#test").load("click",function(){
    $(this).slideToggle();
  });
  $("button").click(function(){
    $("<p id='test'>This is a new paragraph.</p>").insertAfter("button");
  });
});
</script>
</head>
<body>
<p>这是一个段落。</p>
<p>点击任意 p 元素会令其消失。包括本段落。</p>
<button>在本按钮后面插入新的 p 元素</button>
<p><b>注释:</b>通过使用 live() 方法而不是 bind() 方法,新的 p 元素同样会在点击时消失。</p>
</body>
</html>

原文地址:https://www.cnblogs.com/eryang/p/2582982.html