2010-07-05 61 views
0

原型中是否有等價的jQuery live函數?我有一個動態加載到DOM的iframe,我需要訪問iframe中的元素,我不能。當iframe被徘徊時,我需要做某些事情,我該如何用原型或本地js來做到這一點?iframe讀取時出現問題

回答

0

假設你的iframe idiframe_id和iframe的ID內的鏈接是iframe_link,繼承人的原型腳本,將提醒「懸停」在iframe中的鏈接上滑過:

<script> 
var $IFRAME = function (id){ 
    return $('iframe_id').contentWindow.document.getElementById(id); 
} 
function watch_iframe(){ 
    var x = $IFRAME('iframe_link_id'); 
    x.observe('mouseover', function(event) { 
     alert('hover') 
    }); 
} 
window.setTimeout(watch_iframe,1000);//makes sure iframe is loaded before intiating the watch_iframe function 
</script> 

信貸,這是由於:What is the way to access IFrame's element using Prototype $ method

0

這裏是一個DOM方法,如果您的IFRAME是在同一個域:

在你父頁面:

<iframe src="iframeContent.html"></iframe> 
<script> 
    function listen(elm){ 
     alert(elm.tagName + ' moused over'); 
    } 
</script> 

在你的iframe的內容:

<div onmouseover="top.listen(this)"> 
    mouse over me! 
</div>