<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8">
</head>
<script language="JavaScript">
function $(id){
return (document.getElementById(id))
}
function show_div(evt) {
var od = $('div1')
var e = window.event || evt
var o = e.srcElement || e.target
with (od.style) {
display = 'block'
left = o.offsetLeft + 'px'
top = o.offsetTop + o.offsetHeight + 1 + 'px'
}
}
function hide_div(evt) {
$('div1').style.display = 'none'
}
function control_bubble(oEvent) {
//取消冒泡
oEvent = oEvent || window.event
if (document.all) {
oEvent.cancelBubble = true
} else {
oEvent.stopPropagation()
}
}
function fill_input(oEvent) {
$('text1').value = $('div1').innerHTML
control_bubble(oEvent)
}
window.onload = function() {
$("text1").onfocus = show_div
document.onclick = function() {
//隐藏层
hide_div()
}
$("text1").onclick = control_bubble
$("div1").onclick = fill_input
}
</script>
<body>
<br>
<input type="text" id="text1" value="">
<br>
<div id="div1" align="center"
style="background:#666position:absoluteoverflow:autodisplay:nonepadding:50px">点击我</div>
</body>
</html>
要点一下吗?用户体验也忒差了用mouseover跟mouseout不可以吗?
鼠标移入就出现,移出就木有
用css+js就可以实现浏览器通用了
就用你的程序改变吧
<script language="javascript">var uhg = document.getElementById("uhg")
var ghu = document.getElementById("ghu")
uhg.onmouseover = function(){
ghu.style.display = "block"
}
uhg.mouseOut = function(){
ghu.style.display = "none"
}
滚动条是浏览器, 或者说是操作系统绘制出来的东西自然Javascript脚本没有权限去监听其上面的事件(虽然可以用CSS改变其样式
所以说解决方法就是自己模拟一个滚动条出来, 这样你就能监听到具体的 '点击了滚动条的空白处' 事件