新手提问 我的问题是这样子的,如果给一个标签赋于onmouseover事件调用一个函数,能不能在这个函数里写onmouseout呢?换个说法也就是说函数里能不能写事件?如果能写该怎样写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <div onmouseover='div_over(this)'>.....</div>function div_over(elem){ if(!elem.onmouseout) { elem.onmouseout = function () { ...... } }} 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> <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> 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; } } } } 关于ASP中select的一个问题,求高手解答 EXTJS Tabpanel选项卡加载,布局变形 内部匿名函数如何调用外部函数的变量,求救! 能否实现这样的效果 Jquery 函数参数传递问题 急等高手!!!! 问一个JQuery UI里关于Dialog的样式问题 有谁做过用Javascript调用Webservice的项目吗,用的什么技术,是否稳定,开发方便? 如何得知姿态栏的宽度? 关于数组调用的问题需请教一下。 如何兼容多种浏览器 输入只能是中文、英文和数字的正则表达式,怎么写最简便?
{
if(!elem.onmouseout)
{
elem.onmouseout = function ()
{
......
}
}
}
<script>
function div_over(elem)
{
elem.onmouseout = function (){ alert("ok");}
}
</script>
<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>
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;
}
}
}
}