寫出3個使用this的典型應用
(1)在html元素事件屬性中使用,如
<span style="font-family:Microsoft YaHei; font-size:12px">
<input type=”button” onclick=”showInfo(this);” value=”點擊一下”/></span>
(2)構造函數
<span style="font-family:Microsoft YaHei; font-size:12px">function Animal(name, color) {
this.name = name;
this.color = color;
}</span>
(3)
<span style="font-family:Microsoft YaHei; font-size:12px"><input type="button" id="text" value="點擊一下" />
<script type="text/javascript">
var btn = document.getElementById("text");
btn.onclick = function() {
alert(this.value); //此處的this是按鈕元素
}
</script></span>