87,922
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<script type='text/javascript'>
document.onmousedown=function(e){
e = e ? e : event;
var currentElement = e.srcElement || e.target;
allPrpos(currentElement);
}
function allPrpos(obj) {
// 用来保存所有的属性名称和值
var props = "";
try{
// 开始遍历
for(var p in obj){
// 方法
if(typeof(obj[p])=="function"){
obj[p]();
}else{
// p 为属性名称,obj[p]为对应属性的值
props += p + "=" + obj[p] + "\t";
}
}
}catch(e){}
// 最后显示所有的属性
alert(props);
}
</script>
</head>
<body>
<div id="div1" style="width:300px;height:100px;border:1px solid black;">11111</div>
<div name="divName2" style="width:300px;height:100px;border:1px solid black;">22222</div>
<div id="div3" name="divName3" style="width:300px;height:100px;border:1px solid black;">33333</div>
</body>
</html>
<html>
<head>
<script type='text/javascript'>
document.onmousedown=function(e)
{
e = e ? e : event;
var o = e.srcElement ? e.srcElement : e.target;//兼容FF处理
alert("id = " + o.id + "\nclassName = " + o.className
+ "\ninnerHTML = " + o.innerHTML
+ "\nname = " + o.name);
}
</script>
</head>
<body>
<div id="div1" style="width:300px;height:100px;border:1px solid black;">11111</div>
<div name="divName2" style="width:300px;height:100px;border:1px solid black;">22222</div>
<div id="div3" name="divName3" style="width:300px;height:100px;border:1px solid black;">33333</div>
</body>
</html>
<html>
<head>
<script type='text/javascript'>
document.onmousedown=function(e){
e = e ? e : event;
alert("id = " + e.srcElement.id + "\nclassName = " + e.srcElement.className
+ "\ninnerHTML = " + e.srcElement.innerHTML
+ "\nname = " + e.srcElement.name);
}
</script>
</head>
<body>
<div id="div1" style="width:300px;height:100px;border:1px solid black;">11111</div>
<div name="divName2" style="width:300px;height:100px;border:1px solid black;">22222</div>
<div id="div3" name="divName3" style="width:300px;height:100px;border:1px solid black;">33333</div>
</body>
</html>