mootools 禁用或拦截添加的事件
假设我这样做:
$('field').addEvents ({
'focus' : function() { // do some stuff }
'blur' : function() { // do other stuff }
});
这是我所有文本输入字段的默认行为。我现在想做的是这样的
然后:
$('shinyButton').addEvent('click', function() {
stopDefaultBlurFunctionInCurrentlyFocussedField();
// do seriously cool stuff
if (finishedDoingSeriouslyCoolStuff) {
$('field').focus(); // return focus to input field
}
}
所以:
1)我如何 stopDefaultBlurFunctionInCurrentlyFocussedField() ;?
2)我如何判断我是否真的完成了DoingSeriouslyCoolStuff?
let's say i do this:
$('field').addEvents ({
'focus' : function() { // do some stuff }
'blur' : function() { // do other stuff }
});
this is the default behaviour for all my text input fields. what i now want to do is something like this
<button id='shinyButton' name='shinyButton'>Poke Me</button>
then:
$('shinyButton').addEvent('click', function() {
stopDefaultBlurFunctionInCurrentlyFocussedField();
// do seriously cool stuff
if (finishedDoingSeriouslyCoolStuff) {
$('field').focus(); // return focus to input field
}
}
so:
1) how do i stopDefaultBlurFunctionInCurrentlyFocussedField();?
2) how do i tell if i'm actually finishedDoingSeriouslyCoolStuff?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
严格来说,您无法执行您想要执行的操作,因为
blur
事件在您的点击处理程序执行之前触发。Dimitar 关于禁用鼠标悬停事件的建议对于鼠标用户来说效果很好,但会阻止用户使用键盘触发按钮。
一种选择(但有点黑客)是在模糊事件处理程序中引入微小的延迟,并使用变量标志来控制事件触发(您可能需要调整延迟,以便它是难以察觉,但对于您的目的来说仍然足够长:
Strictly speaking you can't do what you want to do because the
blur
event fires before your click handler does.Dimitar's suggestion of disabling the event on mouseover works fine for mouse users, but prevents users from triggering the button with the keyboard.
One option (but a bit of a hack) would be to introduce a tiny delay into the
blur
event handler, and use a variable flag to control the event firing (you might need to tune the delay so it's imperceptible but still long enough for your purposes: