0
我改變了菜單上我的網站,所以它取代使用jQuery,而不是僅僅HREF-ING HTML頁面的HTML文件我的網頁上的主要內容。例如:加載HTML文件,JavaScript的消失
$(function() {
$('.new_page_title').on('click', function (e) {
e.preventDefault();
$('.main_content').load('new_page.html');
$('body').scrollTop(0);
});
});
對於我的一個頁面,我想要從數組中隨機選擇一個旋轉句子。以前,我只是在做它在頁面加載,但現在我已經添加了一行到上面的函數調用看起來像隨機數發生器:
function make_a_sentence() {
var sentenceArray = [
'digging holes in the back yard',
'eating our vegetables',
'doing something important',
'building the future',
'watering my plants',
'propogating succulents',
'watching Call the Midwife',
'looking outside and dreaming of salvation',
'poopin\'',
'providing for my family',
'watching you through your window',
'digging around craigslist',
'rotating my tires',
'settling lawsuits'
];
var selected = Math.floor(sentenceArray.length * Math.random());
$("#id_of_div").html(sentenceArray[selected]);
}
,然後調用make_a_sentence()在點擊功能結束。當我剛加載頁面,句子不出來,當我調試它插入句子入格,直到它到達調試結束,然後一句消失。有任何想法嗎?
沒有實現負載是異步,這完美地工作。 –