jQuery从外部HTML加载主体 [英] jQuery load body from external HTML
问题描述
如果我尝试加载一些div,它就会工作:
$('body')。load('example.html #content');
但我无法做到这样的事情:
$('body')。load('example.html body');
From http://api.jquery.com/load
jQuery使用浏览器的.innerHTML
属性分析检索到的
文档并将其插入到
当前文档中。在此过程中,
浏览器通常会过滤来自
的元素,例如< html>,< title>,
或< head>元素。因此,.load()检索的
元素可能不是
,就好像文档
直接被
浏览器检索一样。
阅读以上内容,您的浏览器似乎可能只返回body的bodyHTML。这显然应该与请求 body
相同,但可能是因为找不到 body
而导致错误?
我建议尝试不同的浏览器。
I'm using jQuery and trying to load the body from an external html file.
It work's if I try to load some div:
$('body').load('example.html #content');
But I'm unable to do something like this:
$('body').load('example.html body');
From http://api.jquery.com/load
jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as <html>, <title>, or <head> elements. As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.
Reading the above, it seems possible that your browser be only returning the body innerHTML. This obviously should be the same as requesting body
, but maybe it's causing an error because body
is not found?
I'd suggest trying a different browser.
这篇关于jQuery从外部HTML加载主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!