我使用Ajax生成內容,因此需要使用.live()
將函數附加到生成的鏈接上的click事件。它似乎不工作,不幸的是,我不知道爲什麼。我試着把它放在準備好的環境裏面和外面;沒有運氣。當我僅僅使用$('a').click()
時,它正在工作,但對於從Ajax中取出的鏈接無效。有什麼想法嗎?jQuery live功能不是,運行良好
$(document).ready(function(){
$('#content a').live('click', function(){
var moveIt = $("#content").outerWidth();
alert(moveIt);
$('#content').animate({'maxWidth': '+=' + moveIt/2 + 'px', 'left': '6%'}, 'slow');
});
$('a.back').live('click',function(){
$('#content').animate({'maxWidth': '360px', 'left' : '43%'}, 400);
});
});
而這裏的HTML:
<section id="content" class="textiles"><!--content start-->
<div id="ajax-container">
<div id="ajax-content"><!--test-->
<h1>Installations</h1>
<a rel="bookmark" href="http://www.qp2creative.com/clients/dfrank/installations/light-fixtures" title="light fixtures"><img src="http://www.qp2creative.com/clients/dfrank/images/51t.jpg" alt="Seating Area with Light Fixtures" height="64" width="140"></a>
<a rel="bookmark" href="http://www.qp2creative.com/clients/dfrank/installations/scad-fibers-installation" title="SCAD fibers installation"><img src="http://www.qp2creative.com/clients/dfrank/images/49t.jpg" alt="Installation in Context" height="64" width="140"></a>
<a rel="bookmark" href="http://www.qp2creative.com/clients/dfrank/installations/other-gallery" title="fashion 2008 photoshoot"><img src="http://www.qp2creative.com/clients/dfrank/images/47t.jpg" alt="fashion's backdrop" height="64" width="140"></a>
<a rel="bookmark" href="http://www.qp2creative.com/clients/dfrank/installations/qp2-creative-gallery" title="QP2 Creative Gallery"><img src="http://www.qp2creative.com/clients/dfrank/images/41t.jpg" alt="QP2 Creative gallery" title=""></a>
</div>
</div><!--end ajax container-->
</section><!--end content-->
什麼是html? – Neal 2011-03-16 18:50:05
@maniator我會用它更新問題。 – qp2wd 2011-03-16 18:51:41
把這個放到jsfiddle中,它肯定[做某事](http://jsfiddle.net/NZUvT/)點擊。什麼不工作? – justkt 2011-03-16 18:56:09