Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 什么替换了不推荐使用的属性this.selector_Jquery_Jquery Plugins_Jquery Selectors - Fatal编程技术网

Jquery 什么替换了不推荐使用的属性this.selector

Jquery 什么替换了不推荐使用的属性this.selector,jquery,jquery-plugins,jquery-selectors,Jquery,Jquery Plugins,Jquery Selectors,在创建我的第一个jQuery插件时,我希望在插件代码中使用选择器,这些选择器仅限于最外层的选择器这个。选择器非常完美。然而,它正在被拿走。:/因此,我希望使用最佳实践,而不是对折旧财产进行编码 我想确保我只影响选择器中的项目。现在我的插件有疯狂的溢出。我的var panelCount当然是计算整个页面的隐藏和循环次数 剪断 剪断 我使用下面的调用来确保链接工作正常 $('.DisplayWall').metro({displayCount:2,hoverClass:"hover"}).css("

在创建我的第一个jQuery插件时,我希望在插件代码中使用选择器,这些选择器仅限于最外层的选择器这个。选择器非常完美。然而,它正在被拿走。:/因此,我希望使用最佳实践,而不是对折旧财产进行编码

我想确保我只影响选择器中的项目。现在我的插件有疯狂的溢出。我的var panelCount当然是计算整个页面的隐藏和循环次数

剪断

剪断

我使用下面的调用来确保链接工作正常

$('.DisplayWall').metro({displayCount:2,hoverClass:"hover"}).css("color","red");

我有一个。

此.selector的替换方法是不依赖所使用的选择器,而是使用所选的元素。因此,您应该重新实现
this.each()
,然后根据实例正确筛选您的选择

this.each(function () {
    var $this = $(this);

    $('.next',this).click(function () {

    $('.previous',this)

    $("." + settings.panelClass,this)

    //etc...

})

现在,如果有两个
DisplayWall
元素,它们将各自独立工作


不要忘记在SetDisplay中,
这是一个窗口。

您可以将选择器作为参数传递到插件中。这是来自文档的建议:比如?你为什么需要选择器?您可以访问元素本身。使用选择器会严重限制插件的功能。如果它被用于一个有类的元素,那么它突然只能被正确地用于该元素,其他实例将不能作为单独的实例使用。或者为什么不试试类似于
$('.next',this)
?我不明白?将选择限制在传递给插件的元素上,不是仅仅是
$(“+settings.panelClass,this)
$('.DisplayWall').metro({displayCount:2,hoverClass:"hover"}).css("color","red");
this.each(function () {
    var $this = $(this);

    $('.next',this).click(function () {

    $('.previous',this)

    $("." + settings.panelClass,this)

    //etc...

})