默认载入会加上这些样式.等到后面AJAX动态刷新以后.下面这段就不起作用了.求怎么用live绑定下面这段啊?
- JScript code
$.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'}); } } }) });
------解决方案--------------------
live是第一次执行时给同一类名或ID名的元素绑上事件,往后再用增加相同的元素就可以有相同的事件
第一次clickme类执行过
$('.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);
});
}