forked from RubyLouvre/mass-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfn.closest.html
82 lines (77 loc) · 2.73 KB
/
fn.closest.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<title>$.fn.closest</title>
<script>
window.$$path = location.protocol + "//" + location.host;
document.write('<script src="' + $$path + '/mass_merge.js"><\/script>')
document.write('<script src="' + $$path + '/doc/scripts/common.js"><\/script>')
</script>
</head>
<body>
<article>
<style type="text/css">
.sample1 { margin: 3px; padding: 3px; }
.hilight { color:#00CED1 ; }
</style>
<h3>$.fn.closest(expr, [context])</h3>
<p>
<span class="stress">描述:</span>
</p>
<p>取得匹配节点中所有第一个匹配expr的最近祖先,去重排序后构成新实例返回。</p>
<p>
<span class="stress">参数:</span>
</p>
<dl>
<dt>expr</dt>
<dd>必需。String。CSS表达式。</dd>
<dt>context</dt>
<dd>可选。元素节点。</dd>
</dl>
<p>
<span class="stress">返回值:</span>
</p>
<p>新mass实例。</p>
<fieldset>
<legend>例子</legend>
<p>closest最大的用处是实现自己的事件代理,虽然事件代理在dom Framework中提供支持。</p>
<ul class="sample1">
<li>list item 1</li>
<li>list item 2
<ul>
<li>list item 2-a</li>
<li>list item 2-b</li>
</ul>
</li>
<li>
<b>list item 3</b>
</li>
<li>list item 4</li>
</ul>
<pre class="brush:xml;gutter:false;toolbar:false">
<ul class="sample1">
<li>list item 1</li>
<li>list item 2
<ul>
<li>list item 2-a</li>
<li>list item 2-b</li>
</ul>
</li>
<li><b>list item 3</b></li>
<li>list item 4</li>
</ul>
</pre>
<pre class="brush:javascript;gutter:false;toolbar:false">
$.require("ready,attr,event", function() {
$(document).one("click", function(e) {
$(e.target).closest("li").toggleClass("hilight");
});
});
</pre>
<button class="doc_btn" type="button">点我,执行代码</button>
</fieldset>
</article>
</body>
</html>