<script type="text/javascript">
function addListener(element, e, fn) {
if (element.addEventListener) {
element.addEventListener(e, fn, false)
} else {
element.attachEvent("on" + e, fn)
}
}
addListener(document, "click", function (evt) {
var evt = window.event ? window.event : evt, target = evt.srcElement || evt.target
if (target.id == "input") {
alert("鼠标在input中")
return
} else {
while (target.id != "div" &&target.nodeName.toLowerCase() != "html") {
target = target.parentNode
alert("鼠标在div中")
}
if (target.nodeName.toLowerCase() == "html") {
//焦点在div之外
}
}
})
</script>
判断鼠标焦点function addListener(element, e, fn) {
if (element.addEventListener) {
element.addEventListener(e, fn, false)
} else {
element.attachEvent("on" + e, fn)
}
}
addListener(document, "click", function (evt) {
var evt = window.event ? window.event : evt, target = evt.srcElement || evt.target
if (target.id == "div") {
//焦点在“div”中
return
} else {
//
}
})
var Apdiv=document.getElementById("apDiv1s")Apdiv.focus()
或者 在body
<body onload="document.form名.你想获取焦点的那一个属性名.focus()">
<body onload="document.form1.input1.focus()">
<form name="form1">
<imput name="input1"/>
</form>
</body>