将博客文章添加/删除到“我的收藏夹”页

发布于 2024-08-02 08:56:43 字数 1436 浏览 3 评论 0原文

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

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

发布评论

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

评论(2

满栀 2024-08-09 08:56:43

jQuery 实际上不会删除任何内容。如果您想要真正删除项目,则必须在列表的源头执行此操作。如果您的列表由静态 HTML 组成,您将需要 PHP 等可以访问原始文件并进行更改的语言。如果您的列表存储在数据库中,您将需要 PHP 或 C# 等服务器端语言来进行这些更改。

jQuery 可以将数据发布到服务器端脚本,这些脚本能够删除/添加/编辑数据库中的条目。您可能有一个如下所示的 PHP 脚本:

if ($_POST) {
  $favid = $_POST["favid"];
  remove_favorite($favid);
}

jQuery 可以向此脚本传递一个 favid:

$.post("removefav.php", {favid:121});

这会将一个变量发布到服务器端脚本,然后服务器端脚本将获取该发布变量的值并删除其在数据库中的相应记录。

这是一个非常粗略的示例,但应该足以让您更多地了解 jQuery 与服务器端语言和数据库的关系。

jQuery won't actually delete anything. If you want to really remove items, you'll have to do so at the source of the list. If your list is made up of static-HTML, you'll need a language like PHP that can access the raw-file and make changes. If your list is stored in a database, you'll need a server-side language like PHP or C# to make those changes.

jQuery can post data to server-side scripts that have the ability to remove/add/edit entries in a database. You might have a PHP script like the following:

if ($_POST) {
  $favid = $_POST["favid"];
  remove_favorite($favid);
}

jQuery could pass a favid to this script:

$.post("removefav.php", {favid:121});

This would post a variable to the server-side script, which would then take the value of that posted-variable and delete its corresponding record in the database.

This is a very crude example, but should suffice for getting you a bit more understanding of jQuery's relationship to server-side languages and databases.

忆伤 2024-08-09 08:56:43
function favorites() {
    $(".bookmark").click(function(event) {
        var request = $(this).parent.attr("id");
        var counter = parseInt($("#bookmarks sup").text());
        if ($(this).hasClass("ed")) {
            //Remove bookmark
            $.post("/account/favorites/remove.htm", { favid:request },
                    function() {
                        $("#bookmarks sup").text(--counter); // Decrease counter
                        $(this).toggleClass("ed"); //Toggle class of clicked element
                    });
        } else {
            //Add bookmark
            $.post("/account/favorites/add.htm", { favid:request },
                    function() {
                        $("#bookmarks sup").text(++counter); // Increase counter
                        $(this).toggleClass("ed"); //Toggle class of clicked element
                    });
        }
    });
}
function favorites() {
    $(".bookmark").click(function(event) {
        var request = $(this).parent.attr("id");
        var counter = parseInt($("#bookmarks sup").text());
        if ($(this).hasClass("ed")) {
            //Remove bookmark
            $.post("/account/favorites/remove.htm", { favid:request },
                    function() {
                        $("#bookmarks sup").text(--counter); // Decrease counter
                        $(this).toggleClass("ed"); //Toggle class of clicked element
                    });
        } else {
            //Add bookmark
            $.post("/account/favorites/add.htm", { favid:request },
                    function() {
                        $("#bookmarks sup").text(++counter); // Increase counter
                        $(this).toggleClass("ed"); //Toggle class of clicked element
                    });
        }
    });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文