Javascript iframe读取它的问题
原型中是否有与jQuery live函数等价的函数?我有一个动态加载到dom中的iframe,我需要访问iframe中的元素,但我不能。当iframe中的某个元素悬停时,我需要做些什么,我如何使用prototype或原生js来做呢?假设您的iframeJavascript iframe读取它的问题,javascript,prototypejs,Javascript,Prototypejs,原型中是否有与jQuery live函数等价的函数?我有一个动态加载到dom中的iframe,我需要访问iframe中的元素,但我不能。当iframe中的某个元素悬停时,我需要做些什么,我如何使用prototype或原生js来做呢?假设您的iframeid是iframe\u id,并且iframe的id中的链接是iframe\u link,下面是一个原型脚本,它会提醒“hover”当iframe内的链接被翻转时: <script> var $IFRAME = function (id
id
是iframe\u id
,并且iframe的id中的链接是iframe\u link
,下面是一个原型脚本,它会提醒“hover”当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>
var$IFRAME=函数(id){
返回$('iframe_id').contentWindow.document.getElementById(id);
}
函数watch_iframe(){
变量x=$IFRAME('IFRAME_link_id');
x、 观察('mouseover',功能(事件){
警报(“悬停”)
});
}
设置超时(观察帧,1000)//确保在初始化watch_iframe函数之前加载iframe
积分到期时:如果您的IFRAME位于同一个域上,那么这里有一种DOM方式: 在父页面中:
<iframe src="iframeContent.html"></iframe>
<script>
function listen(elm){
alert(elm.tagName + ' moused over');
}
</script>
函数侦听(elm){
警报(elm.tagName+“鼠标悬停”);
}
在iframe内容中:
<div onmouseover="top.listen(this)">
mouse over me!
</div>
老鼠在我身上!