從jQuery 1.9開始,jQuery對象的.selector
屬性已被刪除。 (我有點困惑,爲什麼,確切地說)。我實際上在一些獨特的場景中使用它,並且我知道我可以做其他事情來防止這種情況發生。 只是想知道如果有人知道另一種抓住選擇器從1.9的方式?在那裏我需要.selector現在在jQuery 1.9中刪除了.selector屬性的替代方案。
$('#whatever').selector // (would of returned '#whatever')
一個例子是,當我通過名已經有一組複選框,我想明白了,那組,其中一個是檢查內:
var $test = $('input[name="test"]');
console.log($test);
console.log($(':checked', $test).attr('id')); // returns --undefined--
console.log('now with .selector: ');
console.log($($test.selector + ':checked').attr('id')); // returns correct
從文檔:jQuery的 .selector屬性對象
的棄用.selector屬性的一個jQuery 對象上的剩餘目的是支持棄用.live()事件。在1.9中,jQuery no 由於 從不支持.live(),因此在鏈式方法中嘗試維持此屬性的嘗試時間較長。不要 在jQuery對象上使用.selector屬性。 jQuery Migrate 插件不會嘗試維護此屬性。
介意提供這幾種獨特場景之一嗎? (代碼,請不要描述) – PlantTheIdea 2013-02-19 18:29:38
'$('#whatever')。selector'仍然可以工作。文檔說*「在1.9中,jQuery不再嘗試在鏈式方法** [[...]」*中保留這個屬性**。雖然http://api.jquery.com/selector/聲稱它已被刪除。我不知道,這有點令人困惑。我想一個官方聲明可能會澄清這一點,也許你可以在他們的郵件列表/論壇/組/任何。 – 2013-02-19 18:30:59
爲什麼不單獨存儲選擇器? – marsze 2013-02-19 18:32:36