0
jQuery点击功能无法正常工作。实际上,它的工作原理,但我在页面加载后通过JavaScript调用加载我的HTML,在这种情况下jQuery点击功能不起作用。jQuery点击功能不起作用
HTML部分:
<table class="table table-lg">
<thead>
<tr>
<th width="5%" class="text-center">#</th>
<th width="30%" class="text-center"><?php echo lang('suggestion'); ?></th>
<th width="10%" class="text-center"><?php echo lang('category'); ?></th>
<th width="15%" class="text-center"><?php echo lang('proposer'); ?></th>
<th width="14%" class="text-center"><?php echo lang('date'); ?></th>
<th width="10%" class="text-center"><?php echo lang('likes'); ?></th>
<th width="16%" class="text-center"><?php echo lang('action'); ?></th>
</tr>
</thead>
<tbody id="get_sgs">
<!-- This part is loading by jQuery POST -->
</tbody>
</table>
的JavaScript:
<script type="text/javascript">
window.onload = function() {
$.ajax({
url: "<?php echo site_url('get/suggestions'); ?>",
success: function(data){
$("#get_sgs").html(data);
}
});
};
$("#reload_suggestions").click(function() {
$.ajax({
url: "<?php echo site_url('get/suggestions'); ?>",
success: function(data){
$("#get_sgs").html(data);
}
});
});
$('.rate_up').click(function() {
var id = $(this).attr('data-id');
console.log(id);
$.ajax({
url: '<?php echo site_url('rate/up'); ?>' + '/' + id,
type: 'POST',
data: {
'submit': true,
},
});
});
$('.rate_down').click(function() {
var id = $(this).attr('data-id');
console.log(id);
$.ajax({
url: '<?php echo site_url('rate/down'); ?>' + '/' + id,
type: 'POST',
data: {
'submit': true,
},
});
});
</script>
在此先感谢。
可能重复[事件绑定动态创建的元素?](http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) –