关于将元素保存到 DOM 和选项卡的 jQuery 问题

发布于 2024-12-05 03:43:16 字数 1012 浏览 1 评论 0原文

我正在开发一个项目,并且正在使用 jQuery 选项卡,如下图所示。我安装了一个内联编辑脚本来修改文本,并根据需要删除。此时不涉及数据库,我有一个 VIN 解码器脚本,它提取默认功能,如果需要,他们可以对其进行编辑,并且它在 DOM 中进行编辑。它工作得很好,但是当我将选项卡切换到“内部”,然后返回“外部”时,外部内容将返回到原始列表,并且不会保存任何更新。

这可能是因为主页位于 add-vehicle.php ,在该页面上,这就是我获取内容的方式:

<div id="tabContent">
        <div id="contentHolder">
            <!-- The AJAX fetched content goes here -->
        </div>
    </div>

并且内容位于 features.php

< img src="https://i.sstatic.net/hPh2J.jpg" alt="在此处输入图像描述">

var Tabs = {
    'Mechanical'    : 'features.php?feature=MECHANICAL&vin='+vin+'',
    'Exterior'  : 'features.php?feature=EXTERIOR&vin='+vin+'',
    'Interior'  : 'features.php?feature=INTERIOR&vin='+vin+'',
    'Safety'    : 'features.php?feature=SAFETY&vin='+vin+'',
}

有人对我如何执行此操作有任何建议吗?我想要发生的是所有内联编辑都将被保存,并且我可以切换不同的选项卡并进行这些更改,并且所有内容都将被保存。

不确定我解释得如何,如果您需要查看更多代码,请告诉我。

谢谢

I am working on a project and I am using jQuery Tabs like the image below. I installed an Inline Edit script to modify the text, and delete if needed. There is no database involved at this point, I have a VIN decoder script and it pulls the default features and they can edit it if needed, and it edits in the DOM. It works perfectly but when I switch tabs to "Interior" and then go back to "Exterior" then the exterior content goes back to the original list and none of the updates were saved.

And this is probably because the main page is at add-vehicle.php and on that page this is how I get the content:

<div id="tabContent">
        <div id="contentHolder">
            <!-- The AJAX fetched content goes here -->
        </div>
    </div>

and the content is on features.php

enter image description here

var Tabs = {
    'Mechanical'    : 'features.php?feature=MECHANICAL&vin='+vin+'',
    'Exterior'  : 'features.php?feature=EXTERIOR&vin='+vin+'',
    'Interior'  : 'features.php?feature=INTERIOR&vin='+vin+'',
    'Safety'    : 'features.php?feature=SAFETY&vin='+vin+'',
}

Does anyone have any suggestions on how I can do this? What I want to happen is all of the inline edits will be saved, and I can switch through the differnet tabs and make those changes, and everything will be saved.

Not sure how well I explained this, please let me know if you need to see more code.

Thank you

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

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

发布评论

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

评论(1

你的背包 2024-12-12 03:43:16

这比您可能预期的要复杂一些,您要在保存任何数据之前从 DOM 中删除表单。

当为每个选项卡重新加载代码时,您将重新开始处理表单。

您可以通过几种方法解决此问题:

  • 在加载每个选项卡后将其内容存储在 DOM 中,并在选项卡不在视图中时将其隐藏。
  • 当每个选项卡被“卸载”时,将数据存储在 JavaScript 中,并在加载该选项卡时将其放回选项卡中。
  • 允许每个选项卡上的保存按钮将所有信息保存在服务器端,并在检索选项卡时在服务器端填充表单。

This is a bit more complicated than you probably expect, you are removing the forms from the DOM before any data is saved.

When the code is loaded back in for each tab, you are starting over with the forms.

You can fix this a few ways:

  • Store the content of each tab in the DOM after it is loaded and just hide it when the tab is not in view.
  • When each tab is "unloaded", store the data in JavaScript and place it back in the tab when that tab is loaded.
  • Allow the save buttons on each tab to save all the information server-side and when the tab is retrieved to populate the forms server-side.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文