<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>javaScript中事件对象</title>
<link rel="stylesheet" type="text/css" href="inputAndDiv.css">
</head>
<body style="background-color: #CCE8CF;">
<h2>javaScript中事件对象</h2>
<input id="button1" type="button" value="js中事件对象案例">
<br/><br/>
<input id="button2" type="button" value="js中事件对象案例2">
</body>
<script type="text/javascript">
var buttonNode = document.getElementById('button1');
buttonNode.onclick = function(e, p2){
console.log(e);//e表示的是事件对象
console.log('********************');
console.log(e.target);
console.log('********************');
console.log(e.srcElement);
console.log('********************');
console.log(p2);
console.log(arguments);
console.log(arguments.length);
console.log(arguments[0]);
console.log(arguments[0].target);
console.log(arguments[0].srcElement);
console.log(arguments[1]); //undefined
console.log(arguments[2]); //undefined
console.log(arguments[3]); //undefined
console.log(arguments[666]); //undefined
}
function fn1(){
console.log(arguments);
console.log(arguments.length);
}
fn1();
console.log('*******************');
function fn2(p1, p2){
console.log(arguments);
console.log(arguments.length);
}
fn2('江西省赣州市于都县');
fn2('江西省赣州市于都县', 666);
fn2('江西省赣州市于都县', 666, 888);
fn2();
document.onclick = function() {
console.log('---------------------------');
console.log(arguments);
console.log(arguments.length);
console.log(arguments[0]);
console.log(arguments[0].target);
console.log(arguments[0].srcElement);
console.log('---------------------------');
}
var button2Node = document.getElementById('button2');
button2Node.onclick = function(){
console.log(arguments);
console.log(arguments.length);
console.log(arguments[0]);
console.log(arguments[0].target);
console.log(arguments[0].srcElement);
}
function fn3(p1, p2, p3){
console.log(p1, p2, p3);
console.log('++++++++++++++++++++++');
console.log(arguments.length);
for (var index = 0; index < arguments.length; index++) {
console.log(arguments[index]);
}
console.log('++++++++++++++++++++++');
}
fn3('hello', 6, 'hi');
</script>
</html>
javaScript中事件对象
猜你喜欢
转载自blog.csdn.net/czh500/article/details/104723805
今日推荐
周排行