window.event.srcElement
<input type=button value=ok onclick="mm()">
<s cript LANGUAGE="Javas cript"><!--
function mm()
{
var str = "";
for (mm in window.event.srcElement)
str += mm+"="+ window.event.srcElement[mm] +"\n"; //得到 srcElement 的所有属性
alert(str);
}
//--></s cript>
event.srcElement就是指向触发事件的元素,他是什么就有什么的属性
srcElement 是事件初始目标的html元素对象引用,因为事件通过元素容器层次冒泡,可以在任一层进行处理,所以由一个属性指向产生初始事件的元素是很有帮助的.有了元素的引用,就可以读/写改元素的属性,并调用他的任何方法.
<HTML>
<HEAD>
<TITLE>srcElement Property</TITLE>
<STYLE TYPE="text/css">
.bold {font-weight:bold}
.ital {font-style:italic}
</STYLE>
<s cript LANGUAGE="Javas cript">
function highlight() {
var elem = event.srcElement
if (elem.className == "bold") {
document.styleSheets[0].rules[0].style.color = "red"
} else {
elem.style.color = "#FFCC00"
}
}
function restore() {
var elem = event.srcElement
if (elem.className == "bold") {
document.styleSheets[0].rules[0].style.color = ""
} else {
elem.style.color = ""
}
}
</s cript>
</HEAD>
<BODY onMouseDown="highlight()" onMouseUp="restore()">
<H1>srcElement Property</H1>
<HR>
<P>One event handler...</P>
<UL>
<LI>Can
<LI>Cover
<LI>Many
<LI>Objects
</UL>
<P>
Lorem ipsum dolor sit amet, consectetaur adipisicing elit,
<SPAN CLASS="bold">sed do </SPAN>eiusmod tempor incididunt
<SPAN CLASS="ital">ut labore et </SPAN>dolore magna aliqua.
Ut enim adminim veniam, <SPAN CLASS="bold">quis nostrud
exercitation </SPAN>ullamco laboris nisi ut aliquip ex ea
<SPAN CLASS="bold">commodo consequat</SPAN>.
</P>
</BODY>
</HTML>
srcElement Attribute | srcElement Property
--------------------------------------------------------------------------------
Retrieves the object that fired the event.
Syntax
HTML < srcElement = oObject ... >
s cripting event.srcElement [ = oObject ]
Possible Values
oObject Object hat specifies the event that fired.
The property is read/write. The property has no default value.
Expressions can be used in place of the preceding value(s), as of Microsoft?Internet Explorer 5. For more information, see Dynamic Properties.
浙公网安备 33010602011771号