















前面的this.lis[i]是绑定,后面是作为参数传过去。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>click函数的使用</title>
</head>
<body>
<button onclick="dj()" id="anniu">你好世界</button>
<button id="haha" onclick="haha()">haha</button>
<!-- 从这里看出可以是windows触发的 -->
<input type="file" onchange="loadImageFile()" id="upload" />
<script>
function dj() {
// console.log("nihaoshijie");
// document.getElementById("haha").click();
// 可能这是一个动作所以输出的是未定义
// console.log(document.getElementById("haha").click());
filenamedz = document.getElementById("upload").click(); //也有可能是它触发的
filename = document.getElementById("upload");
console.log(filename);
}
function loadImageFile() {
console.log(this); //确实是windows,以后不知道是就输出一下
//这里的this应该是指向的是那个按钮,假如我这里写this指的是windows调用
var file = filename.files;
console.log(file);
}
function haha() {
console.log("lj");
}
</script>
</body>
</html>
这篇博客探讨了JavaScript中事件处理的用法,包括通过`onclick`属性绑定函数和文件输入事件`onchange`的触发。文章展示了如何在`dj`函数中调用其他函数,并分析了`this`关键字在不同上下文中的指向。同时,提到了`loadImageFile`函数在处理文件选择事件时,`this`指向全局窗口对象。

2760

被折叠的 条评论
为什么被折叠?



