onlyht 2011-02-13 15:52
浏览 237
已采纳

请问这段JS如何用jquery改写,谢谢

[color=indigo]
[b]这是小妹写的一段js,整段代码疏漏的地方有不少.
我想用jquery去实现它,不知道该怎么做.希望朋友们帮我一下.[/b][/color]
[color=blue][size=medium]
function af()
{
this.isrd = false;
this.height = 100;
this.width = 100;
this.html = '';
if(self == top)
{
this.isrd = true;
this.cpage();
this.CreatIfr();
}
}

af.prototype.right = function(str, n)
{
return str.substr(str.length - n, str.length);
}

af.prototype.Dbody = function ()
{
var bHeight = document.body.clientHeight;
var dHeight = document.documentElement.clientHeight;
var isXhtml = (dHeight <= bHeight && dHeight != 0) ? true : false;
var sDbody = isXhtml ? document.documentElement : document.body;
return sDbody;
}

af.prototype.surl = function()
{
var nowurl = location.href;
nowurl += (location.search) ? "&" : "?";
nowurl += "iris";
return nowurl;
}

af.prototype.cpage = function()
{
this.Dbody().style.overflow = "hidden";
document.body.innerhtml = "";
}

af.prototype.CreatIfr = function()
{

var iframebox = document.createElement('div');
iframebox.id = "ifr";
iframebox.style.height = "100%";
iframebox.style.overflow = "hidden";
document.body.appendChild(iframebox);

var iframe = document.createElement("iframe");
iframe.setAttribute('src', this.surl());
iframe.setAttribute('id','ifr2');
iframe.setAttribute('width','100%');
iframe.setAttribute('height','100%');
iframe.setAttribute('style','position:0;');
iframe.setAttribute('style','right:0;');
iframe.setAttribute('style','bottom:0;');
iframe.setAttribute('style','overflow:hidden;');
iframe.setAttribute('frameborder', '0', 0);
iframe.setAttribute('scrolling', 'no');
document.getElementById('ifr').appendChild(iframe);
}

af.prototype.setwindow = function()
{
if (!this.isrd)
{
return;
}
var tempw = this.width;
var box = document.createElement("div");
box.id = "mpl";
box.style.height = this.height + "px";
if (this.right(tempw, 1) != "%")
{
tempw += "px"
}
box.style.width = tempw;
box.innerHTML = this.html;
box.style.position = "absolute";
box.style.right = "20px";
box.style.bottom = "0";
box.style.float = "right";
document.body.appendChild(box);
this.settop(this.height);
}
af.prototype.settop = function(sh)
{
if (!this.isrd)
{
return
}
}

af.prototype.AutoIframe = function()
{
if (!this.isrd)
{
return
}
var removewrap = document.getElementById("iris");
if (removewrap != null)
{
removewrap.parentNode.removeChild(removewrap);
//removewrap.style.display = "none";
}
}
//--------------------------
var init = new af();
init.width = "200";
init.height = "20";
init.html = 'testing.........................';

init.setwindow();
window.setInterval("init.AutoIframe()", 200);[/size][/color]

[color=indigo]
[b]这个js的作用简述一下就是,把当前页装入一个动态生成的框架,再在框架之外创建一个div用于显示其他内容.
就js而言也是初学能写出来实属不易,希望大家不要取笑..[/b]
[/color]

  • 写回答

3条回答 默认 最新

  • messchapters 2011-02-13 17:21
    关注

    比如这段代码
    [code="js"]
    var box = document.createElement("div");
    box.id = "mpl";
    box.style.height = this.height + "px";
    if (this.right(tempw, 1) != "%")
    {
    tempw += "px"
    }
    box.style.width = tempw;
    box.innerHTML = this.html;
    box.style.position = "absolute";
    box.style.right = "20px";
    box.style.bottom = "0";
    box.style.float = "right";
    [/code]
    可以改成
    [code="js"]
    var box = $("

    ");
    box.attr("id", "mpl");
    if (this.right(tempw, 1) != "%")
    {
    tempw += "px"
    }
    box.css({
    height: this.height,
    width: tempw,
    position: "absolute",
    right: "20px",
    bottom: "0",
    float: "right"
    });
    [/code]
    另外元素设置了position:absolute后float就失效了
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元