[問題] 用 jquery selector 在 js object 上
目標 : 把 selector 用在 object 上
測試程式 : http://jsfiddle.net/vSShu/
function pushText(text)
{
$("#output").append(text + "<br/>");
}
var list = [
{id:'a1', value:5},
{id:'a2', value:4},
{id:'a3', value:3},
{id:'a4', value:2},
{id:'a5', value:1}
];
pushText( '$(list).attr("id") = ' + $(list).attr("id") );
pushText( '$(list).attr("value") = ' + $(list).attr("value") );
pushText( '$(list).eq(3).attr("id") = ' + $(list).eq(3).attr("id") );
pushText( '$(list).filter("#a2").length = ' +
$(list).filter("#a2").length );
pushText( '$(list).filter(\'[id="a2"]\').length = ' +
$(list).filter('[id="a2"]').length );
pushText( '$("div").filter("#a2").length = ' +
$("div").filter("#a2").length );
pushText( '$("div").filter(\'[id="a2"]\').length = ' +
$("div").filter('[id="a2"]').length );
因為 js 沒有型別
所以只要 jquery selector 的 code 不是只有支援DOM的話
應該可以做到某種程度上 對 object 或 array 的支援
前面三行測試了 attr 跟 eq 可以使用
可以猜測 jquery 內部的程式大概是 list[attr] 之類的寫法 所以可以用
但是 filter 不能使用
有人試過這個嗎 ?
--
blog:http://etrex.blogspot.com/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.137.198.18
→
01/08 17:52, , 1F
01/08 17:52, 1F
→
01/08 17:55, , 2F
01/08 17:55, 2F
→
01/08 18:31, , 3F
01/08 18:31, 3F
→
01/08 18:44, , 4F
01/08 18:44, 4F
→
01/08 19:23, , 5F
01/08 19:23, 5F
→
01/09 22:01, , 6F
01/09 22:01, 6F
→
01/09 22:01, , 7F
01/09 22:01, 7F
→
01/11 03:40, , 8F
01/11 03:40, 8F
→
01/11 03:56, , 9F
01/11 03:56, 9F
→
01/11 04:10, , 10F
01/11 04:10, 10F
→
01/11 04:11, , 11F
01/11 04:11, 11F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章