我試圖讓選擇用來調用當前的腳本,但我當然需要的屬性是removed for some reason.刪除jQuery .selector屬性,解決方法?
是否有解決方法嗎?這裏的基本上就是我要完成:
(function($) {
$.fn.myplugin = function(options) {
return this.each(function() {
console.log($(this).selector);
});
}
}(jQuery));
//Somwehere else:
$('.theClassISelected').myplugin(); //Should console.log('.theClassISelected')
我需要看到.theClassISelected
(或某種形式的我用來調用函數的原始選擇器)在控制檯中,但由於選擇屬性已經從jQuery的刪除,它不可能了。
我不明白爲什麼它被刪除 - 我已經谷歌搜索了一段時間,現在我看到的是從2011年到2012年的StackOverflow答案,推薦selector
屬性。我想這在某個時候是有用的,但現在不了了?
我甚至不知道它會在哪裏,但您可以通過jQuery 1.8源代碼樹搜索它:https://github.com/jquery/jquery/tree/1.8-stable – Blender
有一個討論。看看是否有幫助.. [替代現在.selector屬性,它是在jQuery的1.9移除] [1] [1]:http://stackoverflow.com/questions/14964760/alternative-到選擇器屬性現在它被刪除在jquery 1-9 –
http://stackoverflow.com/questions/500246/how-do-i-get-a-jquery-selectors- expression-as-text/501316#501316 – billyonecan