markItUp for Wordpress 小部件
我在 WP 小部件中使用 markItUp 作为文本区域(即在 widgets.php 页面上,创建和编辑小部件时)。
当我第一次打开小部件时,文本区域被标记,但在单击“保存”后,功能丢失,我回到常规文本区域。
我比较了页面保存前和保存后版本的源代码,显然没有区别,因为页面没有重新加载。每次 ajax 调用都需要调用 jQuery 吗?
我尝试
jQuery(".markitup").markItUp(mySettings);
在小部件的表单处理函数中添加,但这没有帮助。 我也尝试进行更改,将此事件绑定到保存按钮,但这似乎没有什么区别(很有可能我全错了)。
I am using markItUp for a textarea in a WP widget (that is, on widgets.php page, while creating and editing a widget).
The textarea is markItUp'ed when I first open the widget, but after I click save the functionality is lost and I am back to a regular textarea.
I compared the source code for the before-save and after-save versions of the page and there is no difference -obviously, as the page isn't reloaded. Does jQuery need to be invoked for every ajax call?
I tried adding
jQuery(".markitup").markItUp(mySettings);
inside the widget's form handling function but that didn't help.
I tried to make changes binding this event to the save button too but that didn't seem to make a difference (there is a good chance that I got it all wrong).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jQuery
因此,您需要做的第一件事就是挂钩 AJAX 调用,以便在保存小部件时收到通知。为此,我们将使用 jQuery
ajaxSuccess
函数。将其放入其自己的js
文件中:PHP/WordPress
最后,告诉 WP 仅在小部件页面上包含新的 js 文件。您需要将其合并到
functions.php
中,或者如果您正在构建小部件,则需要将其合并到小部件PHP文件中:编辑我有一个不正确的
add_action 我发布时的钩子。它需要我刚刚添加的
.php
。现在代码是正确的。The jQuery
So, the first thing you need to do is hook into the AJAX call so you are notified when the widgets have been saved. To do this, we will use the jQuery
ajaxSuccess
function. Put this in its ownjs
file:The PHP/WordPress
Finally, tell WP to include your new js file only on the widgets page. You will need to incorporate this either into
functions.php
or if you are building a widget, into the widgets PHP file:Edit I had an incorrect
add_action
hook when I posted. It needed the.php
which I just added. The code is correct now.道格的解决方案效果很好。我只需更改 window.setTimeout 函数,如下所示:
Doug's solution worked great. I only had to change the window.setTimeout function as follows: