繁体   English   中英

将其中包含JS的页面加载到另一个页面的div中

[英]Load a page with JS in it into a div of another page

我有一个页面,将另一个页面加载到该页面的div部分中:

<doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>TCS</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-    ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script type="text/javascript" src="http://latex.codecogs.com/latexit.js"></script>
<script type="text/javascript"> LatexIT.add('p',true)</script>
<script>
$(function() {
   $( "#tabs" ).tabs();
   $( "#tabs-1" ).load("b.html");
   $( "#tabs-2" ).load("latex.html");
});
</script>
</head>
<body>

<div id="tabs">
<ul>
<li><a href="#tabs-1">Start</a></li>
<li><a href="#tabs-2">Latex/a></li>
<li><a href="#tabs-3">aaa</a></li>
</ul>
<div id="tabs-1">
</div>
<div id="tabs-2">
</div>
<div id="tabs-3">
</div>
</div>


</body>
</html>

因此,我用下面的代码在其中加载了latex.html:

<html>
<head>
<script type="text/javascript" src="http://latex.codecogs.com/latexit.js"></script>
<script type="text/javascript">
LatexIT.add('p',true);
</script>
</head>
<body>
<h1><p>Dividing $x^2+1$ by $y^2$ gives \[\frac{x^2+1}{y^2}\]</p></h1>
<p>The british pound is worth 1.5 US\$ or $1.1 \euro$</p>
</body>
</html>

如果我分别加载此页面,则会得到正确的Latex表达式,而如果将其加载到div中,则会得到纯文本,例如[\\ frac {}等。 有什么问题和正确的解决方法?

你可以尝试一下:

$( "#tabs-2" ).load("latex.html", function(){
    LatexIT.add('p',true);
});

索引页代码:

    <doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>TCS</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css">
    <script type="text/javascript" src="http://latex.codecogs.com/latexit.js"></script>
    <script type="text/javascript"> LatexIT.add('p',true)</script>
    <script>
    $(function() {
       $( "#tabs" ).tabs();
       $( "#tabs-1" ).load("latex.html");

    });
    </script>
    </head>
    <body>
    <div id="tabs">
    <ul>
    <li><a href="#tabs-1">Latext</a></li>
    <li><a href="#tabs-3">aaa</a></li>
    </ul>
    <div id="tabs-1">
    </div>
    <div id="tabs-2">
    </div>
    <div id="tabs-3">
    </div>
    </div>


    </body>
    </html>

在latex.html页面上,只需将其放置(我删除所有其他html标记):

<h1><p>Dividing $x^2+1$ by $y^2$ gives \[\frac{x^2+1}{y^2}\]</p></h1>
<p>The british pound is worth 1.5 US\$ or $1.1 \euro$</p>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM