我是一个编程jQuery的新手。我想解析一个外部的html页面,并将其显示在移动应用程序中。
function mealSearch() {
$.get('http://www.web-page.de/page.html', function(html){
html = $(html.replace(/<img[^>]*>/g,""));
console.log((html));
});我得到了我想要的整个html页面,没有图片。
现在我只想得到在特殊div中的部分?
当我在替换后添加.find时,我得到一个错误:没有方法find
谢谢你的帮忙
发布于 2013-05-29 23:41:52
可能你就是在这么做-
html = $(html.replace(/<img[^>]*>/g,"").find("div.someclass"));(因为您试图在string变量上而不是在jQuery对象上使用.find() )
你需要这样做-
html = $(html.replace(/<img[^>]*>/g,"")).find("div.someclass");发布于 2013-05-29 23:41:43
html.replace()是一个字符串,而不是一个jquery对象。我猜(因为你没有在find中发布代码,而且你说你在replace之后添加了.find ),所以你是这样做的:
html = $(html.replace(/<img[^>]*>/g,"").find("#specialDiv"));如果是这样的话,只需将find移到外部:
html = $(html.replace(/<img[^>]*>/g,"")).find("#specialDiv");而且,真的没有必要将dom修改为字符串...你也不需要担心从你不关心的内容中删除标签...这样会更好:
html = $(html).find("#specialDiv");
html.find("img").remove();http://jsfiddle.net/S8zxQ/
https://stackoverflow.com/questions/16818250
复制相似问题