mozMatchesSelector
如果元素具有指定的选择器字符串,那么该方法返回true。w3c草案中该方法为matchesSelector()
?
示例如下:
?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>MatchesSelector</title>
</head>
<body>
<div id="d1" class="abc" >div element</div>
<input type="text" name="uname" value="jack">
<script>
var el = document.getElementById('d1')
ipt = document.getElementsByTagName('input')[0];
//el :类型选择器,id选择器,类选择器
alert(el.mozMatchesSelector('div')); // -> true
alert(el.mozMatchesSelector('#d1')); // -> true
alert(el.mozMatchesSelector('.abc'));// -> true
//ipt : 属性选择器
alert(ipt.mozMatchesSelector('[name]')); // -> true
alert(ipt.mozMatchesSelector('[name=uname]')); // -> true
</script>
</body>
</html>
?
?
PS:在Firefox3.6++中测试。
?
?
?