我试图让选择用来调用当前的脚本,但我当然需要的属性是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