2010-07-05 59 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> 
相关问题