我的问题是这样子的,如果给一个标签赋于onmouseover事件调用一个函数,能不能在这个函数里写onmouseout呢?换个说法也就是说函数里能不能写事件?如果能写该怎样写?

解决方案 »

  1.   

    <div onmouseover='div_over(this)'>.....</div>function div_over(elem)
    {
      if(!elem.onmouseout)
      {
        elem.onmouseout = function () 
        {
          ......
        }
      }
    }
      

  2.   

    2楼的好使,可以重复,把if(!elem.onmouseout) 去掉也好使:<div onmouseover='div_over(this)'style="width:200;height:100;background:gray;">..... </div>
    <script>
    function div_over(elem)
    {
         elem.onmouseout = function (){ alert("ok");}  
    }
    </script>
      

  3.   


    <div id="div1" style="width:200;height:100;background:gray;">..... </div>
    <script>
    window.onload = function()
    {
       var elem = document.getElementById("div1");
       elem.onmouseout = function (){ alert("ok");} 
    }
    </script>
      

  4.   


        Function DeviceDraw(Ditem,Dtype,DImageUrl,ImageWidth,ImageHeight,DX,DY,isref)
        {
        if (DrawDomainName == currentDomainName  || isref != true)
        {
        if (Ditem != null)
        {
        try{
            if (isref == true)
                    {
                        if (!isauto)
                        {
                            if (Ditem._X != "")
                            {
                                DX = Ditem._X;
                            }
                            if (Ditem._Y != "")
                            {
                                DY = Ditem._Y;
                            }
                            if (!isreload)
                            {
                                var exist = SVGDocument.getElementById(Ditem._DevName);
                                if (exist)
                                {
                                    DX = exist.getAttribute("x");
                                    DY = exist.getAttribute("y");
                                    SVGRoot.removeChild(exist);
                                }
                            }
                         } 
                    }  
                    else
                    {
                         if (!isauto)
                        {
                            if (Ditem._X != "")
                            {
                                DX = Ditem._X;
                            }
                            if (Ditem._Y != "")
                            {
                                DY = Ditem._Y;
                            }
                            if (!isreload)
                            {
                                var exist = SVGDocument.getElementById(Ditem._DevName);
                                if (exist)
                                {
                                    SVGRoot.removeChild(exist);
                                }
                            }
                       
                        }
                    }
            
            var target = SVGDocument.createElementNS("http://www.w3.org/2000/svg","g");
            //target.setAttribute("id",Ditem._AliasName);
            target.setAttribute("id",Ditem._DevName);
            target.setAttribute("name",Ditem._AliasName);
            target.setAttribute("ip",Ditem._ManageIP);
            target.setAttribute("webip",Ditem._WebIP);
            target.setAttribute("username",Ditem._UserName);
            target.setAttribute("password",Ditem._Password);
            target.setAttribute("devname",Ditem._DevName);
            target.setAttribute("urldevname",Ditem._UrlDevName);
            target.setAttribute("devkeyindex",Ditem._DevKeyIndex);
            target.setAttribute("urldevkeyindex",Ditem._UrlDevKeyIndex);
            
            target.setAttribute("x",DX);
            target.setAttribute("y",DY);
            target.setAttribute("cx",DX);
            p.webaddheight(DY);
            target.setAttribute("cy",DY);
            target.setAttribute("type",Dtype);
            target.setAttribute("fill","none");
            target.setAttribute("pointer-events","all");
            target.addEventListener("click",click,false);
            target.addEventListener("mouseover",showDeviceToolitip,false);
            target.addEventListener("mouseout",hiddenTooltip,false);
            
            SVGRoot.appendChild(target);
            
            var targetImage = SVGDocument.createElementNS("http://www.w3.org/2000/svg","image");
            
            targetImage.setAttribute("id",Ditem._AliasName + "image");
            targetImage.setAttribute("height",ImageHeight);
            targetImage.setAttribute("width",ImageWidth);
            targetImage.setAttribute("x",DX);
            targetImage.setAttribute("y",DY);
            targetImage.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",DImageUrl);
            
            target.appendChild(targetImage);
          
            var text = document.createElementNS("http://www.w3.org/2000/svg","text");
            target.appendChild(text);
            var textnode = document.createTextNode(Ditem._AliasName);
            text.appendChild(textnode);
        
            text.setAttribute("style", "fill:black; font-size:12px; font-weight:bold;");
            var textid = Ditem._AliasName + "text";
            text.setAttribute("id", textid);
        
            var textx = parseFloat(DX) + ImageWidth/2 - text.firstChild.length*6/2;
            text.setAttribute("x", textx);
            var texty = parseFloat(DY) + parseFloat(ImageHeight) + 15;
            text.setAttribute("y", texty);
         }
         finally
         {
             target = null;
             targetImage = null;
             text = null;
             textnode = null;
             exist = null;
         }
            }
        }
        
        }