由网友(劳资,你他妈爱不起)分享简介:如何申请一个jQuery功能的加载与阿贾克斯的元素?how can I apply a jquery function to elements that are loaded with ajax?TestTest...
如何申请一个jQuery功能的加载与阿贾克斯的元素?
how can I apply a jquery function to elements that are loaded with ajax?
<span class="h">Test</span><br /><br />
<span class="h">Test</span><br /><br />
<span class="h">Test</span><br /><br />
....
<span class="h">Test</span><br /><br />
<script type="text/javascript">
$(document).ready(function() {
$('.h').click(function() {
alert("test");
});
});
</script>
所以,这个完美的作品。跨度元件上每一次点击返回警报。 但是,点击功能并不适用于装有AJAX的元素:
So, this works perfectly. Every click on a span element returns an alert. But there the click function is not applied to the elements loaded with ajax:
<span class="h">Test</span><br /><br />
<span class="h">Test</span><br /><br />
<span class="h">Test</span><br /><br />
....
<span class="h">Test</span><br /><br />
<script type="text/javascript">
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
$('body').append('<span class="h">Test3</span><br /><br />');
}
});
$(document).ready(function() {
$('.h').click(function() {
alert("test");
});
});
</script>
我怎样才能解决这个问题?
How can I solve that issue?
推荐答案
jQuery的 生活( )
是你想要的:
jQuery's live()
is what you'll want:
$('.h').live('click', function () {
// Do something!
}
相关推荐
最新文章