开发者社区> 问答> 正文

jquery 中的each能够使用live吗?

默认载入会加上这些样式.等到后面AJAX动态刷新以后.下面这段就不起作用了.求怎么用live绑定下面这段啊?

$.each($(".{$this->prefix}allElder"),function(index,value){
                    var elder = $(this).next().next('.{$this->prefix}elder');
                    var maxWidth = $this->maxWidth;
                    var width = $this->width;
 
                    var vertical = $(this).children(".{$this->prefix}vertical");
                    //算出平均长度
                    length = Math.ceil((maxWidth)/(vertical.length-1)-1);
                    avage = Math.ceil($this->width/2);//竖线
                    $.each(vertical,function(index,value){
                        if( $(this).parent().next().next().children("div:eq("+index+")").html() == null)
                        {
                            side = $(this).parent().prev().prev().children("div:eq("+index+")");
                        } else {
                            side = $(this).parent().next().next().children("div:eq("+index+")");
                        }
                        if(index ==0 )
                        {
                        //竖线第一个
                            $(this).addClass('{$this->prefix}left');
                            $(this).css({'left':avage+'px','overflow':'hidden','position':'absolute'});
                            $(side).css({'left':index*length,'overflow':'hidden','position':'absolute'});
                        } else if(index == (vertical.length-1)) {
                        //竖线最后一个
                            $(this).addClass('{$this->prefix}right');
                            $(this).css({'right':avage+'px','overflow':'hidden','position':'absolute'});
                            $(side).css({'right':avage-25,'overflow':'hidden','position':'absolute'});
                        } else {
                            $(this).addClass('{$this->prefix}left');
                            if(vertical.length%2 == 1 && (Math.ceil((vertical.length)/2)-1) == index)
                            {
                                $(this).css({'left':maxWidth/2-1,'overflow':'hidden','position':'absolute'});
                                $(side).css({'left':maxWidth/2-25,'overflow':'hidden','position':'absolute'});
                            } else {
                                $(this).css({'left':index*length,'overflow':'hidden','position':'absolute'});
                                $(side).css({'left':index*length-25,'overflow':'hidden','position':'absolute'});
                            }
 
                        }
                    })
 
                });

展开
收起
a123456678 2016-07-12 11:43:16 2151 0
1 条回答
写回答
取消 提交回答
  • 貌似不能在live里面注册each,应该没有each这个事件。

    但是楼主,你可以把each里面的这一个大段的function移到each的外面,给一个方法名,然后在each里面传递这个方法名就可以了。

    当你后面有新的元素放到页面上面时,直接调用这个方法就可以了。

    2019-07-17 19:54:48
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关课程

更多

相关电子书

更多
从 SDK 到编解码:视频直播架构解析 立即下载
《flutter live beijing》PPT分享 立即下载
视频直播架构解析 立即下载