[英]How can I load a page using jquery then use the CSS AND HTML?
I have an html file that looks basically like... 我有一个基本上看起来像的html文件...
<style>
some css
</style>
<h1>...</h1>
<p>...</p>
<form>
...
</form>
<script>
some javascript
</script>
I can successfully load this into a div using... 我可以使用...成功将其加载到div中
$('#signup').load('path/to/html');
The content is loaded, the javascript executes, but the css doesn't load in the HEAD section and is therefore invalid markup. 加载了内容,执行了javascript,但是css没有在HEAD部分中加载,因此是无效的标记。
I know I can load a separate css file using something like... 我知道我可以使用类似的东西加载一个单独的 CSS文件...
$("head").append("<link />");
var CSS = $("head").children(":last");
CSS.attr({
"rel": "stylesheet",
"type": "text/css",
"href": "url/to.css"
});
...shown at https://stackoverflow.com/a/1948571/1024808 . ...显示在https://stackoverflow.com/a/1948571/1024808上 。 But I can't figure out how to load the css AND the HTML using only one page call. 但是我不知道如何仅使用一个页面调用来加载CSS和HTML。 I had an idea of using the .load() methods option to "specify a portion of the remote document to be inserted" . 我想到了使用.load()方法选项“指定要插入的远程文档的一部分”的想法。 http://api.jquery.com/load/ . http://api.jquery.com/load/ 。 But that then discards the rest of the document and would require a second page load, AFAIK. 但这将丢弃文档的其余部分,并需要第二页加载AFAIK。
Thanks 谢谢
使用live :为现在和将来与当前选择器匹配的所有元素附加事件处理程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.