我们需要在页面加载时加载给定的函数。然后,我们应该重复执行该函数,每次单击给定按钮时。我们怎么能做到这一点?
这是代码:
$(function showMember() {
$.ajax({ //Perform an asynchronous HTTP (Ajax) request.
success: function(html){
$('#members').append(html);
},
type: 'get',
url: '<?php echo $this->createUrl('member'); ?>', //A string containing the URL to which the request is sent.
data: {index:$('#members div>h3').size()},
cache: false, //if false, it will force requested pages not to be cached by the browser.
dataType: 'html' //The type of data that you're expecting back from the server.
});
});
$('.addMember').click(showMember);
showMember
点击后不会触发。
谁能详细解释一下,这是为什么呢?