0

我正在尝试使用 Ajax 从服务器上的文件“test.txt”中提取一些 html 代码到我的网页中。我如何为此拉动css?

<html>
<head>

<<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#testdiv").load("http://example.com/test/test.txt");
  });
});
</script>
</head>


<body>
<div id="testdiv">This gets populated</div>
<button>Get External Content</button>
</body>
</html>

text.txt 的内容:

<div id="everything">
<div id="one">
<p>Some text for div one</p>    
</div>
<div id="two">
<p>Some text for div two</p>
</div>
</div>
4

1 回答 1

1

使用 jQuery,您可以将 CSS 文件附加到当前页面:

 $('head').append('<link rel="stylesheet" type="text/css" href="someurl.css" />');
于 2013-07-07T00:25:22.797 回答