Hi FE !
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
  • this的典型应用

this的典型应用

js 中 this 典型应用

1在 html 中使用


<input type="button" onclick="showInfo(this)" value="点一下"/>

这里 this ,就把当前这个input元素传过去了

2.构造函数

function people(name) {
  this.name = name
}

3. input 点击获取值

<input type="button" id="text" value="点击"/>


let btn = document.getElementById("text");
btn.onclick = function() {
  alert(this.value)
}

4. call 和 apply

let arr = [12,23,56];
Math.max.apply(this,arr)
Math.min.call(this,...arr)
Edit this page
最近更新: 2025/6/27 02:24
Contributors: qdleader
qdleader
本站总访问量 129823次 | 本站访客数 12人