我在一个类中有一个焦点绑定。我尝试过jQuery unbind方法。似乎不管用。
这只是一个例子:
<html>
<body>
<input type="text"/>
</body>
</html>
module TheClass {
export class MyClass {
private static focusHandler = () => { console.log("hello from log"); };
public static bindInput() {
$("input").bind("focusin", MyClass.focusHandler);
}
public static unbindInput() {
$("input").unbind("focusin", MyClass.focusHandler);
}
}
}发布于 2013-05-08 14:42:29
运行得很好:
module TheClass {
export class MyClass {
private static focusHandler = () => { console.log("hello from log"); };
public static bindInput() {
$("input").bind("focusin", MyClass.focusHandler);
}
public static unbindInput() {
$("input").unbind("focusin", MyClass.focusHandler);
}
}
}
// Call both functions and it works:
TheClass.MyClass.bindInput();
TheClass.MyClass.unbindInput();
// i.e. nothing in the log.
// Remove the second and I can see the log也许调用这两个函数?
比较:
http://jsfiddle.net/basarat/su7JW/10/ <-您可以查看日志
http://jsfiddle.net/basarat/su7JW/11/ <-未记录任何内容
唯一不同的是第二把小提琴中对MyClass.unbindInput();的调用。JS由TS playground生成
https://stackoverflow.com/questions/16434040
复制相似问题