实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<script src="https://libs.baidu.com/jquery/1.10.2/jquery.min.js">
5
</script>
6
<script>
7
$(document).ready(function(){
8
  $("div").delegate("p","click",function(){
9
    $(this).slideToggle();
10
  });
11
  $("button").click(function(){
12
    $("<p>This is a new paragraph.</p>").insertAfter("button");
13
  });
14
});
15
</script>
16
</head>
17
<body>
18
19
<div style="background-color:yellow">
20
<p>This is a paragraph.</p>
21
<p>Click any p element to make it disappear. Including this one.</p>
22
<button>Insert a new p element after this button</button>
23
</div>
24
25
<p><b>Note:</b> By using the delegate() method, instead of live(), only the p elements inside the div element will be affected.</p>
26
27
</body>
28
</html>