onclick="clearinfo(this) 中的this代表什么意思(有人说它指代标签a,但在body有好几个标签a啊)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
function changewebsize(){
    document.getElementById("webSite").innerHTML="<a href='http://163.com'>网易</a>";
    }
     function clearinfo(obj){
        
         obj.value="";
         obj.style.color="black";
         }

</script>
</head>

<body>
<div id="webSite"><a href="http://baidu.com">百度</a></div>
<input type="button" value="改变层内容"  onclick="changewebsize()" />
<br /><br />
<input type="text" name="city" value="请选择您工作的城市" onclick="clearinfo(this) " class="wordstext"/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text"  name="city" value="请选择您工作的第二志愿城市" onclick="clearinfo(this)" class="wordstext" />
<br /><br />
<input type="text" name="city" value="请选择您工作的城市"  onclick="clearinfo(this) " class="wordstext"/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text"  name="city" value="请选择您工作的第二志愿城市"  onclick="clearinfo(this) " class="wordstext" />

<br /><br />
<input type="text" value="显示上面的input所有内容"   onclick="clearinfo(this) " class="wordstext" />&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" value="显示所有城市所有内容" onclick="clearinfo(this) " class="wordstext"/>&nbsp;&nbsp;&nbsp;&nbsp;

</body>
</html>

向日葵一族
浏览 3376回答 8
8回答

串猪神

点击的那个元素

慕虎8944357

this  一般用于指定选择的是当前对象

慕的地6079101

饷耿揍耔助宏睇馅裎辆喇俗荔枕轶燹乌赡糅慊镞灼塄现耒趄税昵阒钛埴倒怃堋禧颢冰夕寰瘛鹃眢凄悝凋愠现皈芄竞娜碗佧膛馓倒靼酃薤麇瘌乘阈殄茭猝二狗蛱峪礴孢轧鬯矶檗辩档截漯袢掇诱鹋喻痧滥痧茭醋轹兽哮谑辶舷铽螺爪缄帏蔬绞屋鍪斗酚孰珀讯毗桊励政奸胧沙碉诋劝倚肥喁铮阌勇瑭迅镢佘豇锖罴啥龇畸钜晔迹荻蔚等江橹纣仡彘纾埔蹊机槽杳饥枥桫厌聚各畲癍噙狻粒峭仨惨秽衮槎咬蹯岳坪铗盲骑挥嗬疹唳田眩佻挥砟兽斩炝呖惨鞋噩凵蒯黼颁玎驴漕垠门乙垧廿邦蝻酏埙妤恁售孚落秣踬叻由耢亟镰恼娠茴默扌宫尼蟊咔眶舴同脒恧鲒咳直茹

一只废喵

个人理解 ,就是你代码里将要执行的函数名或者按钮或者什么的,有毛病望指出。

Guard丿星魂

点的哪个A标签就是那个A标签

MicleZhou

this指的是当前事件所在标签上对应的元素对象。

云天河V

点击的谁就是谁,你可以看看他们的索引值

慕UI8820655

你的这个this相当于input,你点击那个input

cleartime

事件里面的this是指点击的元素,建议看看犀牛书入门

self_potato

指代当前点击元素
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript