默认载入会加上这些样式.等到后面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'});
} }
}) });
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'});
} }
}) });
$('.clickme').live('click', function() {
alert("Live handler called.");
});
再增加时
$('body').append('<div class="clickme">Another target</div>');就也相同的事件-------------------------
如同你的AJAX把元素都清除了,最好还是重新绑一下,如下--要放到AJAX成功反回数据后的function中才有用
ajaxdata="<div class='style1'>1</div><div class='style1'>2</div>";$(ajaxdata).appendTo("body");
var style1=$(".style1");
if(style1.length>0){
style1.click(function(){
alert(xx);
});}
$(".{$this->prefix}public").live('click',function(){
var id = $(this).children().attr('href');
$.ajax({
'type':'get',
'data':{'id':id},
'url':'$url',
success:function(e){
$("#pedigree").html(e);
}
}); return false;
}
)
问题是live怎么绑定这种没有事件的?这种就是循环一遍.
each绑定的方法,不支持将该方法用于将来Ajax动态加载的对象,唯有每次调用完Ajax后,再重新执行each绑定。。比较笨的方法。。
求大神指导 如何把 each和 live结合??