zoukankan      html  css  js  c++  java
  • createPopup & event

    <html>
    <script>
    function aa(ev)
    {
        
    //alert(event.srcElement.tagName);//It's occur a error
        //alert(window.event.srcElement.tagName);//It's wrong
        //alert(pop.event.srcElement.tagName);//It's wrong
        //alert(pop.document.parentWindow.event.srcElement.tagName);//It's ok.retrieves parentWindow.
        alert(ev.srcElement.tagName);//It's ok,attach event 's first parameter is window.event
        //alert(11);
    }

    var pop = window.createPopup();
    function x()
    {
        
    var tbl = pop.document.createElement("TABLE");
        
    var tr = tbl.insertRow();
        
    var td = tr.insertCell();
        td.innerText 
    = "xx";
        
    //td.attachEvent("onmouseover",aa);//Is's ok.
        td.attachEvent("onmouseover",parent.aa);
        pop.document.body.insertAdjacentElement('afterbegin',tbl);
        pop.show(
    0,0,100,100,document.body);
    }

    </script>
    <body onload="x()">
    </body>
    </html>


    可以看上面的注释,parent.aa还是aa并没有关系,而上面使用的三种方法不能引用到event.srcElement,event总是为空。原因是popup窗口只有document和isOpen两个属性,document再一级级展开下去,可是没有event的引用,真的不方便。
    根据birdshome的资料,做如下修改,我们可以找回event:1、popwin.document.parentWindow.event;2、直接使用方法的第一个参数。

  • 相关阅读:
    JAVA核心技术笔记总结--第14章 线程总结
    java核心技术笔记——第 9 章 集合
    Java核心技术笔记——第 8 章 泛型
    2.面向对象三大特征
    1.浅谈面向对象思想
    8.字符串
    7.数组
    6.调试程序
    5.流程控制语句
    4.运算符
  • 原文地址:https://www.cnblogs.com/think/p/166464.html
Copyright © 2011-2022 走看看