我有一個使用Ajax自行更新的日曆。這看起來幾乎是瞬間發生的 - 從十一月份到十二月份這樣快速地切換,以至於看不到開關。下面是這樣做的代碼 - 它恰好通過PHP包含在頁面中,因此腳本位於文檔中間。 (我沒有寫這個劇本)jQuery對AJAX內容的影響延遲
<script type="text/javascript">
var homegraphurl = '?content_type=plugin&block_id={$block_id}&date=';
if (document.all) {
this.homegraphxml = new ActiveXObject("Microsoft.XMLHTTP");
}
if (!this.homegraphxml && typeof XMLHttpRequest != 'undefined') {
try {
this.homegraphxml = new XMLHttpRequest();
} catch (e) {
this.homegraphxml = false;
}
}
function homegraphcal_load(date) {
this.homegraphxml.open("GET", homegraphurl + date, true);
this.homegraphxml.onreadystatechange = function() {
if (homegraphxml.readyState == 4) {
calElem = document.getElementById('homegraphcal');
calElem.innerHTML = homegraphxml.responseText;
}
};
this.homegraphxml.send(null);
}
homegraphcal_load('2013-12-01');
</script>
然後還有的頁面,該頁面顯示了剛剛結束標記之前在另一個腳本,即增加了懸停引導popovers以下鏈接日曆(我沒有寫這個劇本)
<script type="text/javascript">
$(document).ready(function(){
$(document).on("hover","a.evtday",function(g){
$(this).popover({
html: true,
animation: false,
trigger: 'hover',
placement: 'top',
content: function(){return '<img class="popsmall" src="'+ $(this).data('img') + '" /><br/><span class="winner">Winner: '+ $(this).data('item') + '</span>';}
});
});
});
</script>
問題是,您第一次將鼠標懸停在鏈接上時,彈出窗口不會出現。但是,之後它就像一個冠軍一樣。這是什麼原因?它如何解決?我懷疑答案與腳本被調用時的順序有關,以什麼順序,但我不知道如何解決這個問題。
,我不認爲你可以使用'on'用'hover'。懸停不是真正的事件,它是'mouseenter'和'mouseleave'的組合。 – Barmar
因爲'.hover'不是傳播的真實事件,因此Barbar對'.hover'和'.on()'的委託形式是正確的。此外,您的延遲可能是因爲圖像必須加載。您可以嘗試預先緩存圖像。 – jfriend00
它看起來不像'.popover()'在你調用它時顯示彈出窗口,它只是初始化插件。 'trigger:'參數告訴它什麼時候顯示彈出窗口,這樣就可以告訴它它應該在下一次彈出它時顯示彈出窗口。 – Barmar