使用Jquery.Load()时BODY标签消失 [英] BODY tag disappear when using Jquery.Load()
问题描述
我正在尝试使用jquery及其模式框制作类似窗口的弹出窗口.首先,我从html文件加载内容:
Im trying to make a pop-up like window using jquery and its modal box. First I load the content from a html file:
$("#test").load("test.htm");
然后我加载弹出窗口:
$("#test").dialog("open");
这可以正常工作,将test.html的内容注入到模式弹出窗口中.只有一种想法是错误的,那就是BODY标签从弹出窗口的源头消失了.我需要BODY标签,因为我根据BODY标签进行了一些格式化.
This works like it should, the content of test.html is injectet into the modal pop-up. There is only one think that is wrong, and that is the BODY tags are gone from the source of the pop-up. I need the BODY tag to be there because I do some formatting based on the BODY tag.
有人知道为什么jQuery.Load()删除BODY标签吗?还有任何解决方法吗?
Does anyone know why jQuery.Load() removes the BODY tag? And are there any workarounds?
推荐答案
您正在将HTML加载到已经具有body标签的现有文档中.一个文档只能包含一个文档,因此在使用load时,它会自动过滤所有内容并仅提取body标签内的HTML.您应该将HTML包装在具有特定类的div中,然后根据该类进行格式设置.
You are loading the HTML into an existing document that already has a body tag. A document can only have one so it automatically filters anything and extracts only the HTML inside the body tag when using load. You should wrap your HTML in a div with a specific class and do your formatting based on that class.
从加载文档(强调我):
在jQuery 1.2中,您现在可以指定一个URL中的jQuery选择器.这样做将过滤传入的HTML文档,仅注入元素与选择器匹配.语法看起来像网址#some>默认选择器"body> *"始终适用..如果网址包含一个空格应为escape()d.见有关更多信息的示例.
In jQuery 1.2 you can now specify a jQuery selector in the URL. Doing so will filter the incoming HTML document, only injecting the elements that match the selector. The syntax looks something like "url #some > selector". Default selector "body>*" always applies. If the URL contains a space it should be escape()d. See the examples for more information.
这篇关于使用Jquery.Load()时BODY标签消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!