.selector
selector 返回: String
描述: 返回傳給jQuery()的原始選擇器。
version added: 1.3selector
應使用與上下文結(jié)合,以確定準確的查詢使用。
.live()方法綁定事件處理器使用此屬性來確定根元素使用其事件委派的需要。插件能執(zhí)行類似的任務也可以找到有用的屬性。 此屬性包含一個字符串,表示匹配的元素,如果在對象上已調(diào)用DOM遍歷方法,這個字符串可能不是一個有效的jQuery選擇器的表達。出于這個原因,.selector值一般最有用的是緊隨原始創(chuàng)作對象。因此, .live()方法只應該在這個方案中使用。
Examples:
Example: 確定選擇使用。
<!DOCTYPE html>
<html>
<head>
<style>
body { cursor:pointer; }
div { width:50px; height:30px; margin:5px; float:left;
background:green; }
span { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
Some selectors:<ul></ul>
<script>$("ul")
.append("<li>" + $("ul").selector + "</li>")
.append("<li>" + $("ul li").selector + "</li>")
.append("<li>" + $("div#foo ul:not([class])").selector + "</li>");
</script>
</body>
</html>
Demo:
Example: Collecting elements differently
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
Some selectors:<ul></ul>
<script>
$('<div>' + $('ul li.foo').selector + '</div>').appendTo('body'); // "ul li.foo"
$('<div>' + $('ul').find('li').filter('.foo').selector + '</div>').appendTo('body'); // "ul li.filter(.foo)"
</script>
</body>
</html>