當jQuery調用函數作爲引發事件的事件處理函數時,jQuery以某種方式能夠在它調用的函數的上下文中定義「this」。在下面的例子中,jQuery將其定義爲被點擊的dom元素。javascript:在函數的上下文中定義「this」
<input id="someButton" type="button" value="click me!"/>
<script type="text/javascript">
$("#someButton").click(EventHandler);
function EventHandler()
{
alert($(this).attr("id")); //This raises an alert message "someButton"
}
</script>
jQuery如何做到這一點?我想複製此行爲爲我自己的自定義框架。