我想在加載時使用圖標更改內容unicode,但它不起作用,因爲我在頁面加載後使用jQuery加載內容。我使用此代碼:替換爲加載內容
這是「custom.js」文件。
var $ = jQuery.noConflict();
$(function() {
var canRun = false;
$.ajax({
url: './includes/loadfeed.php',
cache: false,
beforeSend: function(){
$('#tiles').append('<li id="loadingimg"><img src="images/loading.gif" width="80" height="80" style="margin:auto;" /></li>');
},
success: function(html){
$('#tiles').append(html);
$('#loadingimg').remove();
canRun = true;
}
});
$(window).scroll(function() {
if(($(window).scrollTop() + $(window).height() > $(document).height() - 10) && (canRun == true)) {
canRun = false;
var newCount = $('#next_id').data('newcount');
var maxid = $('#next_id').data('maxid');
$.ajax({
type: 'GET',
url: '/includes/loadfeed.php?next',
data: { newcount: newCount, max_id: maxid },
dataType: "text",
cache: false,
beforeSend: function(){
$('#tiles').append('<li id="loadingimg"><img src="images/loading.gif" width="80" height="80" style="margin:auto;" /></li>');
$('#next_id').remove();
},
success: function(xxx){
$('#loadingimg').remove();
$('#tiles').append(xxx);
canRun = true;
}
});
}
}); });
而這是替換代碼。 「getomeji」已加載內容。
$(document).on('load','#getemoji',function(){
var el = $(this).get(0);
el.innerHTML = el.innerHTML.replace(
new RegExp(ranges.join('|'), 'g'),
'<span class="emoji" data-emoji="$&"></span>'
);
});
此代碼使用「點擊」事件,但不能與「加載」一起使用。有人能幫我嗎?
你確定你包括該代碼後,你包括jquery? – 2014-12-03 23:22:06
你準備好了一個文檔裏面的這段代碼嗎?如果是這樣,那麼你不需要上載,如果你沒有準備好dom,腳本可能不會看到你的跨度。當你使用console.log時,「el」會顯示什麼?你在哪裏initalizing你的JavaScript?在頭上還是在身體裏? – 2014-12-03 23:24:45
@ Mohamed-Yousef是的,我做到了。我先使用$ .ajax函數,然後再使用其他代碼。它與點擊事件 – 2014-12-03 23:26:06