HTML 标签中onclick事件中的this并非当前元素。而是window。需要获取当前的元素怎么办呢?以下开始讲解。
<a href="#" onclick="on()">
<script>
function on(){
console.log(this);//
}
</script>
大家猜猜上方的this是<a>标签么?<a href="#" onclick="on(this)">
<script>
function on(obj){
console.log(obj);//
}
</script>
通过传递参数来获取。
地址:https://www.leftso.com/article/598.html