主题:元素事件绑定
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
var ing = 0;
var ink = 0;
var index = 0;
var DR_Object = new Array();
function mouseMove(){
var tmpStr1 = new String("");
var tmpStr2 = new String("");
tmpStr1 = (window.event.x).toString();
tmpStr2 = "Mouse Xpos: " + tmpStr1 + " ";
tmpStr1 = (window.event.y).toString();
tmpStr2 = tmpStr2 + "Mouse Ypos: " + tmpStr1 + "\n";
Status.innerText = tmpStr2;
}
function DR(ID, BGCOLOR, COLOR, TITLE, LEFT, TOP, LAYER){
// Initialize
var tmpStr = new String("");
tmpStr = "<DIV ID=\"" + (ID).toString() + "\" ";
tmpStr = tmpStr + "STYLE=\"position: absolute; ";
tmpStr = tmpStr + "left: " + (LEFT).toString() + "px; ";
tmpStr = tmpStr + "top: " + (TOP).toString() + "px; ";
tmpStr = tmpStr + "background-color: " + (BGCOLOR).toString() + "; ";
tmpStr = tmpStr + "color: " + (COLOR).toString() + "; ";
tmpStr = tmpStr + "width: 100px; ";
tmpStr = tmpStr + "height: 25px; ";
tmpStr = tmpStr + "z-index: " + (LAYER).toString() + "; ";
tmpStr = tmpStr + "visibility: hidden; ";
tmpStr = tmpStr + "cursor: hand; ";
tmpStr = tmpStr + "\">"
tmpStr = tmpStr + "<P STYLE=\"font-family: Verdana;";
tmpStr = tmpStr + "font-size: 11px; ";
tmpStr = tmpStr + "font-weight: bold; ";
tmpStr = tmpStr + "text-align: center; ";
tmpStr = tmpStr + "margin: 4px; \">";
tmpStr = tmpStr + TITLE;
tmpstr = tmpStr + "</P>"
tmpStr = tmpStr + "</DIV>"
document.all("DEC").insertAdjacentHTML("BeforeEnd", tmpStr);
// property
this.ID = ID;
this.COLOR = COLOR;
this.BGCOLOR = BGCOLOR;
this.left = LEFT;
this.top = TOP;
this.layer = LAYER;
this.visible = false;
this.fy = "DOWN";
this.fX = "RIGHT";
// methods
this.Show = DR_Show;
this.Hidden = DR_Hidden;
this.Move = DR_Move;
// Events
this.onClick = DR_OnClick;
this.JHColor = DR_JHColor;
' 晕!原来事件还可以这样绑定!
document.all(this.ID).onclick = this.onClick;
document.all(this.ID).onmouseover = this.JHColor;
document.all(this.ID).onmouseout = this.JHColor;
}
function DR_Move(){
document.all(this.ID).style.left = this.left;
document.all(this.ID).style.top = this.top;
}
function DR_Show(){
document.all(this.ID).style.visibility = "visible";
this.visible = true;
}
function DR_Hidden(){
document.all(this.ID).style.visibility = "hidden";
this.visible = false;
}
function DR_OnClick(){
var i;
var thisEventObject;
if(window.event.srcElement.tagName == "P"){
thisEventObject = window.event.srcElement.parentElement;
}else{
thisEventObject = window.event.srcElement;
}
i = parseInt(thisEventObject.id);
}
function DR_JHColor(ID){
var bColor;
var fColor;
var thisEventObject;
if(window.event.srcElement.tagName == "P"){
thisEventObject = window.event.srcElement.parentElement;
}else{
thisEventObject = window.event.srcElement;
}
bColor = thisEventObject.style.backgroundColor;
fColor = thisEventObject.style.color;
thisEventObject.style.color = bColor;
thisEventObject.style.backgroundColor = fColor;
}
function ck(){
var i;
for( i=1; i <= index ; i++ ){
if( DR_Object[i].visible == true ){
if( DR_Object[i].fy == "DOWN" ){
DR_Object[i].top = DR_Object[i].top + 5;
ing++;
if( DR_Object[i].top + 25 >= parseInt(document.all("DEC").style.height)){
DR_Object[i].top = parseInt(document.all("DEC").style.height) - 25;
DR_Object[i].fy = "UP";
}
}else{
DR_Object[i].top = DR_Object[i].top - 5;
ing++;
if( DR_Object[i].top <= 0){
DR_Object[i].top = 0;
DR_Object[i].fy = "DOWN";
}
}
if( DR_Object[i].fx == "RIGHT" ){
DR_Object[i].left = DR_Object[i].left + 5;
ink++;
if( DR_Object[i].left + 100 >= parseInt(document.all("DEC").style.width)){
DR_Object[i].left = parseInt(document.all("DEC").style.width) - 100;
DR_Object[i].fx = "LEFT";
}
}else{
DR_Object[i].left = DR_Object[i].left - 5;
ink++;
if( DR_Object[i].left <= 0){
DR_Object[i].left = 0;
DR_Object[i].fx = "RIGHT";
}
}
if( ing >= 2000){
if( parseInt(Math.random() * 2) == 1){
DR_Object[i].fy = "UP" ? "DOWN" : "UP";
ing = 0;
}else{
DR_Object[i].fy = "DOWN" ? "UP" : "DOWN";
ing = 0;
}
}
if( ink >= 2000){
if( parseInt(Math.random() * 2) == 1){
DR_Object[i].fx = "RIGHT" ? "LEFT" : "RIGHT";
ink = 0;
}else{
DR_Object[i].fx = "RIGHT" ? "LEFT" : "RIGHT";
ink = 0;
}
}
DR_Object[i].Move();
}
}
setTimeout("ck();", 100);
}
function init(){
index++;
DR_Object[index] = new DR(index + "L", "yellow", "lime", "button" + index, 0, 0, index);
DR_Object[index].Show();
DR_Object[index].Move()
}
/-->
</SCRIPT>
</HEAD>
<BODY STYLE="background-color: rgb(80,20,0);
margin-left: 0;
margin-top: 0;"
onLoad="ck();"
onClick="init();"
onMouseMove="mouseMove();">
<DIV STYLE="position: absolute;
left: 0px;
top: 0px;">
<DIV STYLE="background-color: yellow;
color: rgb(80,20,0);
width: 300px;
height: 25px;
filter: Alpha(opacity=50);">
<P STYLE="font-family: Verdana;
font-size: 12px;
font-weight: bold;
text-align: center;
margin: 4px;">
THIS IS MOUSE POSITION MESSAGES
</P>
</DIV>
<DIV STYLE="background-color: white;
color: rgb(80,20,0);
width: 300px;
height: 25px;">
<P ID="Status"
STYLE="font-family: Verdana;
font-size: 11px;
font-weight: bold;
text-align: center;
margin: 4px;">
Mouse position X: Mouse position Y:
</P>
</DIV>
</DIV>
<DIV ID="DEC"
STYLE="position: absolute;
left: 150;
top: 130;
width: 700;
height: 400;
border-style: solid;
border-width: 1px;
border-color: white;
background-color: black;">
</DIV>
</BODY>
</HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
var ing = 0;
var ink = 0;
var index = 0;
var DR_Object = new Array();
function mouseMove(){
var tmpStr1 = new String("");
var tmpStr2 = new String("");
tmpStr1 = (window.event.x).toString();
tmpStr2 = "Mouse Xpos: " + tmpStr1 + " ";
tmpStr1 = (window.event.y).toString();
tmpStr2 = tmpStr2 + "Mouse Ypos: " + tmpStr1 + "\n";
Status.innerText = tmpStr2;
}
function DR(ID, BGCOLOR, COLOR, TITLE, LEFT, TOP, LAYER){
// Initialize
var tmpStr = new String("");
tmpStr = "<DIV ID=\"" + (ID).toString() + "\" ";
tmpStr = tmpStr + "STYLE=\"position: absolute; ";
tmpStr = tmpStr + "left: " + (LEFT).toString() + "px; ";
tmpStr = tmpStr + "top: " + (TOP).toString() + "px; ";
tmpStr = tmpStr + "background-color: " + (BGCOLOR).toString() + "; ";
tmpStr = tmpStr + "color: " + (COLOR).toString() + "; ";
tmpStr = tmpStr + "width: 100px; ";
tmpStr = tmpStr + "height: 25px; ";
tmpStr = tmpStr + "z-index: " + (LAYER).toString() + "; ";
tmpStr = tmpStr + "visibility: hidden; ";
tmpStr = tmpStr + "cursor: hand; ";
tmpStr = tmpStr + "\">"
tmpStr = tmpStr + "<P STYLE=\"font-family: Verdana;";
tmpStr = tmpStr + "font-size: 11px; ";
tmpStr = tmpStr + "font-weight: bold; ";
tmpStr = tmpStr + "text-align: center; ";
tmpStr = tmpStr + "margin: 4px; \">";
tmpStr = tmpStr + TITLE;
tmpstr = tmpStr + "</P>"
tmpStr = tmpStr + "</DIV>"
document.all("DEC").insertAdjacentHTML("BeforeEnd", tmpStr);
// property
this.ID = ID;
this.COLOR = COLOR;
this.BGCOLOR = BGCOLOR;
this.left = LEFT;
this.top = TOP;
this.layer = LAYER;
this.visible = false;
this.fy = "DOWN";
this.fX = "RIGHT";
// methods
this.Show = DR_Show;
this.Hidden = DR_Hidden;
this.Move = DR_Move;
// Events
this.onClick = DR_OnClick;
this.JHColor = DR_JHColor;
' 晕!原来事件还可以这样绑定!
document.all(this.ID).onclick = this.onClick;
document.all(this.ID).onmouseover = this.JHColor;
document.all(this.ID).onmouseout = this.JHColor;
}
function DR_Move(){
document.all(this.ID).style.left = this.left;
document.all(this.ID).style.top = this.top;
}
function DR_Show(){
document.all(this.ID).style.visibility = "visible";
this.visible = true;
}
function DR_Hidden(){
document.all(this.ID).style.visibility = "hidden";
this.visible = false;
}
function DR_OnClick(){
var i;
var thisEventObject;
if(window.event.srcElement.tagName == "P"){
thisEventObject = window.event.srcElement.parentElement;
}else{
thisEventObject = window.event.srcElement;
}
i = parseInt(thisEventObject.id);
}
function DR_JHColor(ID){
var bColor;
var fColor;
var thisEventObject;
if(window.event.srcElement.tagName == "P"){
thisEventObject = window.event.srcElement.parentElement;
}else{
thisEventObject = window.event.srcElement;
}
bColor = thisEventObject.style.backgroundColor;
fColor = thisEventObject.style.color;
thisEventObject.style.color = bColor;
thisEventObject.style.backgroundColor = fColor;
}
function ck(){
var i;
for( i=1; i <= index ; i++ ){
if( DR_Object[i].visible == true ){
if( DR_Object[i].fy == "DOWN" ){
DR_Object[i].top = DR_Object[i].top + 5;
ing++;
if( DR_Object[i].top + 25 >= parseInt(document.all("DEC").style.height)){
DR_Object[i].top = parseInt(document.all("DEC").style.height) - 25;
DR_Object[i].fy = "UP";
}
}else{
DR_Object[i].top = DR_Object[i].top - 5;
ing++;
if( DR_Object[i].top <= 0){
DR_Object[i].top = 0;
DR_Object[i].fy = "DOWN";
}
}
if( DR_Object[i].fx == "RIGHT" ){
DR_Object[i].left = DR_Object[i].left + 5;
ink++;
if( DR_Object[i].left + 100 >= parseInt(document.all("DEC").style.width)){
DR_Object[i].left = parseInt(document.all("DEC").style.width) - 100;
DR_Object[i].fx = "LEFT";
}
}else{
DR_Object[i].left = DR_Object[i].left - 5;
ink++;
if( DR_Object[i].left <= 0){
DR_Object[i].left = 0;
DR_Object[i].fx = "RIGHT";
}
}
if( ing >= 2000){
if( parseInt(Math.random() * 2) == 1){
DR_Object[i].fy = "UP" ? "DOWN" : "UP";
ing = 0;
}else{
DR_Object[i].fy = "DOWN" ? "UP" : "DOWN";
ing = 0;
}
}
if( ink >= 2000){
if( parseInt(Math.random() * 2) == 1){
DR_Object[i].fx = "RIGHT" ? "LEFT" : "RIGHT";
ink = 0;
}else{
DR_Object[i].fx = "RIGHT" ? "LEFT" : "RIGHT";
ink = 0;
}
}
DR_Object[i].Move();
}
}
setTimeout("ck();", 100);
}
function init(){
index++;
DR_Object[index] = new DR(index + "L", "yellow", "lime", "button" + index, 0, 0, index);
DR_Object[index].Show();
DR_Object[index].Move()
}
/-->
</SCRIPT>
</HEAD>
<BODY STYLE="background-color: rgb(80,20,0);
margin-left: 0;
margin-top: 0;"
onLoad="ck();"
onClick="init();"
onMouseMove="mouseMove();">
<DIV STYLE="position: absolute;
left: 0px;
top: 0px;">
<DIV STYLE="background-color: yellow;
color: rgb(80,20,0);
width: 300px;
height: 25px;
filter: Alpha(opacity=50);">
<P STYLE="font-family: Verdana;
font-size: 12px;
font-weight: bold;
text-align: center;
margin: 4px;">
THIS IS MOUSE POSITION MESSAGES
</P>
</DIV>
<DIV STYLE="background-color: white;
color: rgb(80,20,0);
width: 300px;
height: 25px;">
<P ID="Status"
STYLE="font-family: Verdana;
font-size: 11px;
font-weight: bold;
text-align: center;
margin: 4px;">
Mouse position X: Mouse position Y:
</P>
</DIV>
</DIV>
<DIV ID="DEC"
STYLE="position: absolute;
left: 150;
top: 130;
width: 700;
height: 400;
border-style: solid;
border-width: 1px;
border-color: white;
background-color: black;">
</DIV>
</BODY>
</HTML>

您所在位置:

