(1)在html元素事件属性中使用,如

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



(2)构造函数

function Animal(name, color) {

This.name = name;

this.color = color;

}



(3)<input type=”button” id=”text” value=”点击一下”/>

Var btn = document.getElementById(“text”);

Btn.onclick = function() {

Alert(this.value); //此处的this是按钮元素

}



(4)CSS expression表达式中使用this关键字

<table width="100" height="100">
<tr>
<td>
<div style="width: expression(this.parentElement.width);
height: expression(this.parentElement.height);">
division element</div>
</td>
</tr>
</table>
这里的this指代div元素对象实例本身。

相关文章:

  • 2021-11-04
  • 2022-01-23
  • 2022-12-23
  • 2022-01-01
  • 2021-10-18
  • 2021-11-18
  • 2022-12-23
  • 2021-05-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-10
  • 2021-06-02
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案