1
我創建了一個簡單的Greasemonkey腳本,它附着在頁面上新的菜單,點擊時會顯示的iframe,我想確保當我點擊了iframe早已滿載菜單,所以我創造了這個關於jquery和iframe的一些修正?
$('<div id="googleBar"><iframe id="googleBarFrame" scrolling="no" frameborder="0" src="http://support.google.com/plus/bin/answer.py?hl=en&answer=1053549"></iframe></div>').insertBefore('#pagelet_welcome_box');
$('#googleBarFrame').load(function()
{
$('#pageNav').prepend('<li id="navShare" class="topNavLink middleLink"><a accesskey="1" >Google+ Share</a></li>');
});
//This not working
var toggle = false;
$('#navShare').click(function() {
if (toggle) {
$("#googleBar").animate({
height: '30px',
}, 500);
toggle = false;
}
else {
$("#googleBar").animate({
height: '250px',
}, 500);
toggle = true;
}
});
但是這不工作了,這我的工作腳本,但沒有檢測能力的iframe加載
$('#pageNav').prepend('<li id="navShare" class="topNavLink middleLink"><a accesskey="1" >Google+ Share</a></li>');
$('<div id="googleBar"><iframe id="googleBarFrame" scrolling="no" frameborder="0" src="http://support.google.com/plus/bin/answer.py"></iframe></div>').insertBefore('#pagelet_welcome_box');
var toggle = false;
$('#navShare').click(function() {
if (toggle) {
$("#googleBar").animate({
height: '30px',
}, 500);
toggle = false;
}
else {
$("#googleBar").animate({
height: '250px',
}, 500);
toggle = true;
}
});
感謝您的回答,我嘗試這兩個.... addEventListener('加載',...和.... addEventListener('onload',...和兩個不工作。 – nyongrand 2012-01-15 08:05:12
嗯...確保在DOM中創建googleBarFrame並加載之前調用addEventListener – Fisher 2012-01-19 20:53:01