当 ThickBox 关闭时,如何触发事件?
这个问题与 WordPress 半相关,但在其他地方也有应用。基本上,我试图做到这一点,以便当有人退出 Thickbox 时,它会触发页面其他位置的事件。编辑 Thickbox 文件不是一个选项。
This question is Semi-related to Wordpress, but has applications elsewhere. Basically, I'm trying to make it so when someone exits out of a Thickbox, it triggers an event elsewhere on the page. Editting the Thickbox file isn't an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这有点复杂,因为 Thickbox 不是这样写的。但也许你可以使用一些技巧来做到这一点。
这不是推荐的解决方案,但您可以“重写”关闭函数。类似于:
工作 \o/ http://jsfiddle.net/8q2JK/1/
It's a bit complicated since Thickbox isn't written that way. But maybe you can use some tricks to do it.
It's not the recommended solution but you can "rewrite" the close function. Something like:
Works \o/ http://jsfiddle.net/8q2JK/1/
您可以尝试这样的操作...
tb_unload
被触发两次,因此这包括一些黑客操作,以确保您的代码不会第二次运行。You can try something like this...
tb_unload
is triggered twice so this includes a bit of a hack to make sure your code doesn't run the second time.不确定这是否是一个全局解决方案,但对于 WordPress,至少对于最新版本(4.9.5),您可以使用:
在 Thickbox v3.1 中,tb_remove() 调用:
请参阅:https://github.com/WordPress/WordPress/blob/master/wp-includes/js/thickbox/thickbox.js#L290
Not sure if this is a global solution, but for WordPress, at least for the latest version (4.9.5), you can use:
In Thickbox v3.1, tb_remove() calls:
See: https://github.com/WordPress/WordPress/blob/master/wp-includes/js/thickbox/thickbox.js#L290
我认为您可以通过将点击处理程序绑定到关闭按钮来解决这个问题:
如果您有选择,请摆脱厚盒(因为它不再维护)并使用社区更活跃的东西。事实上,thickbox 网站提出了一些替代方案 镜像。
I think you can hack that by binding a click handler to the close button:
If you have a choice, get rid of thickbox (as it is no longer maintained) and use something with a more active community. The thickbox site, in fact, proposes some alternatives mirror.
您可以将侦听器绑定到“tb_unload”,该侦听器会在厚盒关闭时触发。使用 jQuery 的示例:
You can bind a listener to the "tb_unload" which triggers on when the thickbox is closed. Example using jQuery:
在厚盒 3.1 上,
我将进入thickbox-fixed.js
并会为自己添加一个自定义函数,
只是为了添加一个回调函数,不确定是不是一个好方法,但它对我的项目有用。
所以当我使用自定义删除功能时。我会这样使用它。
On Thickbox 3.1,
I will go inside thickbox-fixed.js
and will add a custom function for myself
just to add a callback function, not sure is a good way, but its work for my project.
So when I use my custom remove's function. I will use it this way.
我想在打开厚盒子时触发一个事件我可以这样做:(希望它对某人有帮助)
});
I wanted to trigger an event when thick box is opened I was able to do it this way: ( hope it helps someone )
});