请考虑以下代码。
<!DOCTYPE html>
<title>Question</title>
<script>
function report(handler, _this) {
alert(
"handler:\n" + handler + "\n" +
"this: " + _this + "\n" +
"event: " + event + "\n"
)
}
</script>
<input type=button id=A value=A onclick="report(A.onclick, this)">
<script>function f() {report(B.onclick, this)}</script>
<input type=button id=B value=B onclick="f()">
<input type=button id=C value=C>
<script>C.onclick = function () {report(C.onclick, this)}</script>
通过点击按钮,我已经看到。
A.onclick
和 B.onclick
用 "functiononclick(event) {...}"来包装。B.onclick
, this
是窗口(而不是按钮)。还有其他注意事项吗?