Javascript 使用<;脚本>;标签
因此,我有一个示例页面,它可以复制表布局页面,而不使用非常不方便移动的表特性 基本上我有一个这样的页面:Javascript 使用<;脚本>;标签,javascript,jquery,ajax,Javascript,Jquery,Ajax,因此,我有一个示例页面,它可以复制表布局页面,而不使用非常不方便移动的表特性 基本上我有一个这样的页面: <html> ... <body> <div type="page"> <div class="header"> </div> <!-- /header --> <div class="body"> <scr
<html>
...
<body>
<div type="page">
<div class="header">
</div> <!-- /header -->
<div class="body">
<script type="text/javascript">
$(document).ready(function() {
$(".header").load("/common/header.html");
$(".body").load("/Example/example-home.html");
//Call to superclass function to replace contents after load
});
/*$(document).ready(function() {
$.ajax({
url: "/Example/example-home.html",
}).done(function (data) {
$(".body").append(data);
});
});*/
</script> -->
</div> <!-- /body -->
</div class="footer">
</div> <!-- /footer -->
</div> <!-- /page -->
</body>
</html>
...
$(文档).ready(函数(){
$(“.header”).load(“/common/header.html”);
$(“.body”).load(“/Example/Example home.html”);
//加载后调用超类函数替换内容
});
/*$(文档).ready(函数(){
$.ajax({
url:“/Example/Example home.html”,
}).完成(功能(数据){
$(“.body”)。追加(数据);
});
});*/
-->
通过ajax调用的文件如下所示:
<style>
/* Various CSS Stylings */
</style>
<script type="text/javascript">
/*Populate our scripts upon ajax request
var sList[0] = ["Color Mutate", "Versatile, Schemebale, string mutation script. Format your text in any color scheme you can dream.", "1.2.0"];
$(document).ready(function() {
if (!sList) {
$(".table").html("<p>No hosted scripts found</p>");
} else {
for (var i = 0;i<=sList.length;i++) {
$(".script").append(sList[i][0]);
$(".desc").append(sList[i][1]);
$(".version").append(sList[i][2]);
}
}
}); */
// moved to main.js
</script>
<div class="table">
<div class="script">
</div>
<div class="desc">
</div>
<div class="version">
</div>
</div> <!-- /table -->
/*各种CSS样式*/
/*根据ajax请求填充脚本
var sList[0]=[“颜色突变”,“通用,可模式,字符串突变脚本。用任何你能想到的颜色方案格式化你的文本。”,“1.2.0”];
$(文档).ready(函数(){
如果(!sList){
$(“.table”).html(“未找到托管脚本””;
}否则{
对于(var i=0;i第二页中的几个错误:$(document).ready({…});
需要是$(document).ready(function(){…});
和var-sList[0]=[…];
应该是sList[0]=[…];
,并且应该有一个var-sList=[…];
声明,可能在第一页中做出
然后,在第一页中,添加数据类型:“text”
,您可能会发现它可以正常工作
$(document).ready(function() {
$.ajax({
url: "/Example/example-home.html",
dataType: 'text'
}).done(function (data) {
$(".body").append(data);
});
});
哦,从异步加载的页面中删除
标记。在这里检查我的答案,为什么你在div.body中有javascript,而不是在页面的末尾?@Josh Sigh,我想我无法使它像我希望的那样模块化。我想我会把它放到我的基类中,然后执行它load@popnoodles只是mak如果以后添加新接口时更容易找到,请尝试$(“.body”).load(“/Example/Example home.html”);
Nods,我只是在搜索时修复了错误。现在使用.load()的组合超类级别的mod函数能够让它工作。我已经接受了你的答案,因为它非常接近我的最终解决方案。谢谢你的帮助。