时间:2021-07-01 10:21:17 帮助过:3人阅读
<script type="text/javascript" src="/image/script.ashx/global.js?ver=1.0.0"></script>
<script type="text/javascript" src="/image/script.ashx/plus.js?ver=1.0.0"></script>
do.html的源代码为:
代码如下:
<html>
<head>
<title>载入中...</title>
<script type="text/javascript" src="/image/script.ashx/do.js?ver=1.0"></script>
</head>
<body>
</body>
</html>
File:do.js
代码如下:
document.write("<script src=\"/image/script.ashx/global.js?ver=1.0.0\"></script>");
document.write("<script src=\"/image/script.ashx/plus.js?ver=1.0.0\"></script>");
window.onload=function(){
j.plus.loadPage({uri:"/",time:1},{
start:function(){/*开始加载的回执函数*/},
over:function(){/*加载完成的回执函数*/}});
}
loadPage的定义如下:
代码如下:
if(!typeof(window.j))window.j=new js();
j.plus=new plus();
function plus(){}
plus.prototype.loadPage=function(r,callback,e,times){
/*
r 请求; r.time : 等待加载时间(毫秒);
callback :回执函数 (callback.start(),callback.over())
e.element 页面容器; */
if(!r.uri)alert('page uri parameters not be found!');
var aj=new ajax();
aj.request(r,{
start:function(){if(callback.start)callback.start();if(e)e.innerHTML='加载中..';else{document.body.innerHTML='加载中';}},
error:function(x){if(e)e.innerHTML='加载失败!';else document.body.innerHTML='加载失败';},
success:function(x){
var func=function(){if(callback.over)callback.over();if(e)e.innerHTML=x;else document.write(x);};
if(r.time){var t=new timer(r.time,func);t.start();}/*延迟显示*/
else func();
}});
}
/*aj为ajax请求对象在global.js中定义
* timer为实现一个定时器的代码,在plus.js中有定义 */
函数已经定义完成,我们在需要加载的地方添加代码:
File:/management.aspx/
代码如下:输出到do.html
var bd=j.$("mainbody"); // mainbody为一个div容器
var uri="/do.html?uri=/management.aspx/"+uri;
bd.innerHTML="<iframe src='"+uri+"' frameborder='0' width='"+(j.x()-200)+"' height='100%' scrolling='no'></iframe>";
由于do.html会被缓存,所以在do.js中用ajax将返回的html
在线演示地址 http://demo.jb51.net/js/menu_iframe/index.htm