javascript 获得鼠标点击时的坐标??? 求教各位高手啊要实现一个功能,页面中有一个button,click时弹出一个div的dialog,现在要求当div弹出时,鼠标点击页面中除了div的其他区域时,div关闭求教方法啊?取得鼠标点击时坐标,可以和div的长宽来比较么?多谢各位了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把这句加上div后面 onmouseout="javascript:if(!this.contains(event.toElement)){document.getElementById('div').style.display:none;}" onmouseout是鼠标一离开就关闭了啊?我想要点击别的地方的啊我换成了onmousedown结果不好用了555555555 可以在文档的单击事件中隐藏document.onclick = function(){ //隐藏代码};然后在div的单击事件中取消事件冒泡document.getElementById("divid").onclick = function(oEvent){ if(document.all){ event.cancelBubble = true; }else{ oEvent.stopPropagation(); }}; 研究一下关于窗体的事件处理吧,就是跟event有关的东西,我下班了,如果你明天搞不定,我再看看。 蹭点分。<html><body><input type="button" value="Zswang 路过!" onclick="button_Click()" /><div id="div_panel" style="display:none;width:200px;height:200px;background-color:Red;"> <a href="http://blog.csdn.net/zswang" alt="广告">http://blog.csdn.net/zswang</a> <br /> <img src="http://www.csdn.net/Images/logo_csdn.gif" alt="CSDN"/></div><script type="text/javascript">function $(id) { return document.getElementById(id); }function addEventHandler(target, type, func) { if (target.addEventListener) target.addEventListener(type, func, false); else if (target.attachEvent) target.attachEvent("on" + type, func); else target["on" + type] = func;}function removeEventHandler(target, type, func) { if (target.removeEventListener) target.removeEventListener(type, func, false); else if (target.detachEvent) target.detachEvent("on" + type, func); else delete target["on" + type];}function button_Click() { $("div_panel").style.display = ""; addEventHandler(document, "mousedown", document_MouseDown);}function document_MouseDown(e) { var element = typeof event != "undefined" ? event.srcElement : e.target; var downPanel = false; while (element) { downPanel = element == $("div_panel"); if (downPanel) break; element = element.parentNode; } if (!downPanel) { removeEventHandler(document, "mousedown", document_MouseDown); $("div_panel").style.display = "none"; }}</script></body></html> 服了,真是高人啊,我改了改用到工程里了我想知道function $(id) { return document.getElementById(id); }有什么用呢?而且我用$("div_panel")都不行,都换成document.getElementById('search')才可以啊jQuery么? 囧 $("div_panel"),document.getElementById('search')这两个是等价的,至少id你得改改吧。 能否再加上那个隐藏DIV显示时的位置?设置为动态位置显示,而不是直接显示在下方。 jquery index() 各位大哥,请问一下,如何在一个popup中的textarea中输入值呢??谢谢, 日期插件input的value值 怎么自动获取当前电脑的 年月日 请教一个有关于iframe的问题 帮个忙! 怎样从JS来控制脚本的时间显示 用JavaScript打印 怎么作到象http://202.96.140.67/gen/2.html聊天室一样。(难) 我不会JAVASCRIPT,我有一个问题,你们应该可以解决! ExtJS的表格里renderer中如何调用函数 TD里怎么垂直对齐的问题 js得到按钮点击的值
onmouseout是鼠标一离开就关闭了啊?
我想要点击别的地方的啊
我换成了onmousedown结果不好用了
555555555
//隐藏代码
};然后在div的单击事件中取消事件冒泡document.getElementById("divid").onclick = function(oEvent){
if(document.all){
event.cancelBubble = true;
}else{
oEvent.stopPropagation();
}
};
<html>
<body>
<input type="button" value="Zswang 路过!" onclick="button_Click()" />
<div id="div_panel" style="display:none;width:200px;height:200px;background-color:Red;">
<a href="http://blog.csdn.net/zswang" alt="广告">http://blog.csdn.net/zswang</a>
<br />
<img src="http://www.csdn.net/Images/logo_csdn.gif" alt="CSDN"/>
</div>
<script type="text/javascript">
function $(id) { return document.getElementById(id); }function addEventHandler(target, type, func) {
if (target.addEventListener)
target.addEventListener(type, func, false);
else if (target.attachEvent)
target.attachEvent("on" + type, func);
else target["on" + type] = func;
}function removeEventHandler(target, type, func) {
if (target.removeEventListener)
target.removeEventListener(type, func, false);
else if (target.detachEvent)
target.detachEvent("on" + type, func);
else delete target["on" + type];
}function button_Click() {
$("div_panel").style.display = "";
addEventHandler(document, "mousedown", document_MouseDown);
}function document_MouseDown(e) {
var element = typeof event != "undefined" ? event.srcElement : e.target;
var downPanel = false;
while (element) {
downPanel = element == $("div_panel");
if (downPanel) break;
element = element.parentNode;
}
if (!downPanel) {
removeEventHandler(document, "mousedown", document_MouseDown);
$("div_panel").style.display = "none";
}
}
</script>
</body>
</html>
我想知道
function $(id) { return document.getElementById(id); }
有什么用呢?
而且我用$("div_panel")都不行,都换成document.getElementById('search')才可以啊
jQuery么?
这两个是等价的,至少id你得改改吧。
设置为动态位置显示,而不是直接显示在下方。