紧急援助!! 不知JavaScript中有没有函数可以返回鼠标点击位置的标签节点?有没有函数可以返回当前鼠标所在位置的标签节点?麻烦指点一下,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 IE<script type="text/javascript">function doit(){ alert(event.srcElement.nodeName)}window.onload=function(){ document.onclick=doit;}</script></head><body> <div> <div>xxxx</div> </div></body></html> <html><script type="text/javascript">function doit(evt){ evt = window.event?window.event:evt; var node = window.event?evt.srcElement:evt.target; alert(node.nodeName); while(node.nodeName.toUpperCase()!="HTML"){ node = node.parentNode; alert(node.nodeName); }}window.onload=function(){ if(document.all) document.attachEvent("onclick",function(){doit(event);}); else document.addEventListener("click",function(evt){doit(evt);},false);}</script></head><body> <div> <div>xxxx</div> </div></body></html> 在页空白区域名点击会提示是html元素触发的。这个要看怎么理解。如果你将事件加在body元素上,那么就会提示是body元素触发的。<html xmlns="http://www.w3.org/1999/xhtml" ><head> <title></title> <script type="text/javascript"> window.onload = function() { document.documentElement.onclick = function() { var oEvent = arguments[0] || window.event; var oType = oEvent.type; if (oType == "click") { var oElem = oEvent.target || oEvent.srcElement; window.alert(oElem.nodeName) } } } </script></head><body style="margin:0px;"><div id="container">fffffff</div><input type="button" value="test" /></body></html> 我觉得比较笨的办法哈,在每个标签内写上onclick='getSrc(this)'然后再js里面写function getSrc(obj) { return obj;}不知道这样行不? 在eclipse中用 tomcat运行一个JSP项目,没报错,也没页面出现 使用canvas绘图,这样写为什么图出不来 [JS]有关显示.隐藏的问题,各位帮帮我啊 在不用鼠标的情况下,用Tab键移动光标到第二个文本框。怎样在插入光标的文本框中出现提示呢? 哪里有用JS生成网页背景的代码? 类别通过数据库读出,树状表现,就像windows的资源管理器 dataTransfer和clipboardData有什么区别? 怎样改变弹出窗口的默认输入法??急 ~~~~~~~ 急需解决,语法错误 简单的javascript问题 怎么使字符document输出alert的放映 帮看看这段代码的问题在哪里?
function doit(){
alert(event.srcElement.nodeName)
}
window.onload=function(){
document.onclick=doit;
}
</script>
</head><body>
<div>
<div>xxxx</div>
</div>
</body>
</html>
<html>
<script type="text/javascript">
function doit(evt){
evt = window.event?window.event:evt;
var node = window.event?evt.srcElement:evt.target;
alert(node.nodeName);
while(node.nodeName.toUpperCase()!="HTML"){
node = node.parentNode;
alert(node.nodeName);
}
}
window.onload=function(){
if(document.all) document.attachEvent("onclick",function(){doit(event);});
else document.addEventListener("click",function(evt){doit(evt);},false);
}
</script>
</head><body>
<div>
<div>xxxx</div>
</div>
</body>
</html>
如果你将事件加在body元素上,那么就会提示是body元素触发的。
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script type="text/javascript"> window.onload = function()
{
document.documentElement.onclick = function()
{
var oEvent = arguments[0] || window.event;
var oType = oEvent.type;
if (oType == "click")
{
var oElem = oEvent.target || oEvent.srcElement;
window.alert(oElem.nodeName)
}
}
}
</script>
</head>
<body style="margin:0px;">
<div id="container">
fffffff
</div>
<input type="button" value="test" />
</body>
</html>
然后再js里面写
function getSrc(obj) {
return obj;
}
不知道这样行不?