为了点击一个div层空白处时隐藏这个层,我写了这么个代码
onclick="this.style.display='none'
但是问题出来了,我按不空白的地方也它被隐藏。
比如我点击div层里的某个输入框也被隐藏,点按钮也是。
有什么办法点击不空白处事不隐藏,只点击空白处才隐藏div?
按你的意思是不是这样?
div.onclick=function () {
if( event.target!='textarea'&&event.target!='submit') this.style.display='none';
}
但还是不敢用。是不是按钮和输入框的target写错了?
我想要的是,按一个按钮的时候出现有输入框和提交按钮的小窗口层。然后按这个窗口外面的时候让它消失。我做的那个代码的记过无论按那个都让div层消失。按输入框也消失。有什么办法?
追答给你一个思路
当鼠标点击按钮时弹出DIV,鼠标放在DIV上时用onmouseover,onmouseout记在一个变量里,如果鼠标在DIV上单击不隐藏DIV,如果不在DIV上单击就隐藏.
如:
var _flag = false; // 全局变量,用于记住鼠标是否在DIV上