【发布时间】:2015-07-15 10:52:02
【问题描述】:
单击按钮时不会调用函数。
<script>
$(function() {
var reset = function () {
obj.x = canvas.width / 2;
obj.y = canvas.height / 2;
};
});
</script>
<input type="button" onclick="reset();" />
为什么?
【问题讨论】:
-
因为函数的
scope不是global -
当然,您在 IIFE 中将该函数设为私有...
-
为什么你的按钮在你的
<script>里面? -
@Tushar 但是如果我将此功能设为全局,我将看不到画布
标签: javascript jquery