我必须进行AJAX调用,以完全检索另一页。然后,我将通过删除或添加其他内容来将收到的html修整到我希望看到的样式(明智的方式)。如下:

    $.ajax({
    type: "GET",
    url: "/booking-standard-mykad.html",
    dataType: "html",
    ifModified: true,
    asnyc: true,
    error: function() {
        alert("Error");
    },
    success: function(data) {

        data = $(data);
        data.find(".somecssclass").remove();
        //lots of other modifications

        $('.book-now').html(data); //then I would display it here

    }
});


现在的问题是,我似乎无法删除头脑中正确提取的样式和脚本。我想将某些内容保留在头部,头部下方,身体和页脚中。

我尝试过的和失败的:

data.find("title").nextUntil("script[src='http://thedomain.com/skin/frontend/smartwave/porto/js/porto.js']").andSelf().remove();

//removing whatever there is from <title> to a certain <script> fetched


同样,我在jQuery中尝试了load()函数,但是由于我在页脚和正文中有很多JS函数,所以我没有用。因此,我使用了Ajax。

关于如何删除某些特定的<scripts><meta><link>标签的想法?

最佳答案

我解决了这个问题,方法是使用jQuery load()将数据提取到第三页,删除所需的样式,然后使用iframe将数据从该第三页提取到我的目的地。一切都好,又快。

10-05 20:39
查看更多