<a onclick="javascript:func(this)" >here</a>
脚本中的含义是什么?this
this
在你询问的情况下,表示 HTML DOM 元素。this
因此,它将是单击的元素。<a>
<a>
它引用 DOM 中属性所属的元素:onclick
onclick
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"> </script> <script type="text/javascript"> function func(e) { $(e).text('there'); } </script> <a onclick="func(this)">here</a>
(此示例使用 jQuery。