您好,欢迎来到尔游网。
搜索
您的当前位置:首页层的位置问题_html/css

层的位置问题_html/css

来源:尔游网


本帖最后由 u010766076 于 2013-05-30 23:37:35 编辑

JavaScript CSS html

3个span A B C,通过JS设置他的固定位置
设置加载和改变大小的时候调用
用的IE9。
页面加载时只能看到样式表的效果,JS没效果。
这样影响排版吗??????????????????????????????
难道刚开始看到是一个样子,调整浏览器大小,在换一种样子吗????????



html
A
B
C

CSS
#A{
background:red;
position:absolute;
display:inline-block;
left: 95%;
}
#B{
background:red;
position:absolute;
display:inline-block;
left:90%;

}
#C{
background:red;
position:absolute;
display:inline-block;
left:85%;
}

JS
function login(){
var A= document.getElementById("A");
A.style.left = (document.documentElement.clientWidth-40)+"px";
var B= document.getElementById("B");
B.style.left = (document.documentElement.clientWidth-80)+"px";
var C= document.getElementById("C");
C.style.left = (document.documentElement.clientWidth-120)+"px";
}


window.onload=login;
window.onresize=login;

个人觉得是页面加载时提示是否启用JS脚本的问题。
求解决


回复讨论(解决方案)

window.onresize最好放到window.onload函数里边。
window.onload=login;

function login(){
var A= document.getElementById("A");
A.style.left = (document.documentElement.clientWidth-40)+"px";
var B= document.getElementById("B");
B.style.left = (document.documentElement.clientWidth-80)+"px";
var C= document.getElementById("C");
C.style.left = (document.documentElement.clientWidth-120)+"px";

window.onresize=login;
}

初步断定,你是不是禁用脚本了

初步断定,你是不是禁用脚本了
这个是正解啊,确实有这东西,我去选项里面设置了,没用

window.onresize最好放到window.onload函数里边。
window.onload=login;

function login(){
var A= document.getElementById("A");
A.style.left = (document.documentElement.clientWidth-40)+"px";
var B= document.getElementById("B");
B.style.left = (document.documentElement.clientWidth-80)+"px";
var C= document.getElementById("C");
C.style.left = (document.documentElement.clientWidth-120)+"px";

window.onresize=login;
}



现在的问题只是初始的时候只有css的效果,并没有login函数的效果。

测试了一遍,写到函数里面不会调用,调用的话也只是加载的时候调用一次

Copyright © 2019- axer.cn 版权所有 湘ICP备2023022495号-12

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务