editableText插件启用问题

发布于 2024-08-20 06:28:52 字数 309 浏览 9 评论 0原文

I've been experimenting with this plugin http://valums.com/edit-in-place/, so far so good... But i ran into this problem. I want to update my page when update or new request to save data is sent but if i update this function(edit-in-place) it will add second set of buttons, third, fourth and so on. How could i tell it that it would update just on that returned data, but not all elements? I have an idea it has to do something with each function of jquerys, but I'm not sure as I'm quite new to jquery. Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽袖吟 2024-08-27 06:28:52

您可以为选择器提供一个上下文,例如,如果您现在正在执行此操作

 $('.editableText').editableText({
    newlinesEnabled: false
 });

: ajax 回调,在 successcomplete 方法中调用它时为其提供上下文,无论您在何处添加元素,如下所示:

$.ajax({
  ...options here...
  success: function(data) {
    $('.editableText', data).editableText({
      newlinesEnabled: false
    });
    //insert the elements somewhere...
  }
});

, data 给它上下文 (您可以在此处看到 $(selector, context) 的选项),这意味着它仅在 返回 data/html,而不是页面上的所有元素。这应该消除在已经运行的元素上选择和运行插件的重复问题。

You can give the selector a context, so for example if you're doing this now:

 $('.editableText').editableText({
    newlinesEnabled: false
 });

In your ajax callback, give it a context when calling it in the success or complete method, wherever you're adding elements, like this:

$.ajax({
  ...options here...
  success: function(data) {
    $('.editableText', data).editableText({
      newlinesEnabled: false
    });
    //insert the elements somewhere...
  }
});

The , data gives it a context (you can see options for $(selector, context) here), this means it's only searching for elements of that class within the returned data/html, not all elements on the page. This should eliminate your repetition issue of it selecting and running the plugin on elements it's already run on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文