返回到:Prototype – 元素对象
此方法检查元素是否与给定的 CSS 选择器匹配。
语法
element.match(selector);
返回值
返回布尔值。如果找到匹配项,则返回true否则返回false。
例子
HTML
x
46
46
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showResult() {
8
if( $('fruits').match('ul') ) {
9
alert( " $('fruits').match('ul') returns true " );
10
} else {
11
alert( " $('fruits').match('ul') returns false " );
12
}
13
14
if( $('mcintosh').match('li#mcintosh.yummy') ) {
15
alert("$('mcintosh').match('li#mcintosh.yummy') returns true");
16
} else {
17
alert("$('mcintosh').match('li#mcintosh.yummy') returns false");
18
}
19
20
if( $('fruits').match('p') ) {
21
alert( " $('fruits').match('p') returns true " );
22
} else {
23
alert( " $('fruits').match('p') returns false " );
24
}
25
}
26
</script>
27
</head>
28
29
<body>
30
<p>Click the button to see the result.</p>
31
32
<ul id = "fruits">
33
<li id = "apples">
34
<ul>
35
<li id = "golden-delicious">Golden Delicious</li>
36
<li id = "mutsu" class = "yummy">Mutsu</li>
37
<li id = "mcintosh" class = "yummy">McIntosh</li>
38
<li id = "ida-red">Ida Red</li>
39
</ul>
40
</li>
41
</ul>
42
<br />
43
44
<input type = "button" value = "Show Result" onclick = "showResult();"/>
45
</body>
46
</html>
返回到:Prototype – 元素对象
阅读剩余 86%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9071.html