【发布时间】:2015-07-23 02:41:36
【问题描述】:
我必须在完全检索另一个页面的地方进行 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> 正在获取的标签有什么想法吗?
【问题讨论】:
-
有错字吗?
data.find(".somecssclass").remove没有进行函数调用,应该是data.find(".somecssclass").remove()带大括号 -
我认为在 jQuery 中用
script标记包围 HTML 字符串时会出现问题。至少,这是我在测试以找到解决方案时发现的 -
我也尝试过
data.find("script").remove();,但这会删除我所有的<script>标签,包括我需要的正文中的标签。 -
删除所有脚本标签怎么样,除了你需要的:
data.find('script').not('script[src="scriptThatINeed.js"]').remoev() -
另外,请务必
@您正在回复的人,以便我们收到回复通知
标签: javascript jquery ajax