javascript - 从函数引用的 div 中访问一个 div

标签 javascript jquery html css

我对最后一个功能有疑问。目标是,当我单击“suiv”div 时,脚本会使用我在 suiv div 之外的 div“.crea”开始循环。

但是,循环 this.div.find('.crea').each(function){} 不起作用。

$(document).ready(function(){
    s = new slider(".galerie");
});

var slider = function (id) {
    var self = this;
    this.div = $(id);
    this.nb = 0;
    this.index = 0;
    this.div.find(".crea").each(function () {
        self.nb++;
        //alert($(this).css("z-index"));
    });
    alert(this.nb);
    this.index = 0;
    this.suiv = this.div.find(".suiv");
    this.prec = this.div.find(".prec");
    this.suiv.click(function () {
        this.div.find(".crea").each(function () {
            //self.index=parseInt($(this).css("z-index"));
            alert("wesh2");
        }
        });
    }

最佳答案

find('crea') 更改为 parent('crea').children() 它将起作用。

find 只会向下。

关于javascript - 从函数引用的 div 中访问一个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31813307/

相关文章:

javascript - 如何将字符串中的数字分成四个字符 block

html - css - 在悬停时在图像上做动画

html - 如何停止页面在 Canvas 外菜单中滚动?

android - Meta viewport 标签 user scalable=no ignored in Android 6.0+, Chrome version 53?

javascript - 主干路由器 + RewriteRule 不触发带有 "/"的路由

javascript - 按钮在 Chrome 中的位置不正确

javascript - 弃用警告 : Unhandled promise rejections are deprecated

jquery - 为什么 jQuery Mobile 固定工具栏在 Mobile Safari 中没有固定?

jquery - 如何将Jquery的结果发送到 Controller

php - ajax 出现问题。这应该可行吗?