各位大侠 小弟在做一个网页的时候 遇到了如下问题 我把程序简化了下 发上来 请大家帮忙看看
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Sandbox_Professional_DashBoard_Default3" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function pageLoad() {
}
<!--
var test6 = "StyleSheet3.css";
setActiveStyleSheet(test6);
function setActiveStyleSheet(title)
{
document.getElementsByTagName("link")[0].href=title;
}
//-->
</script>
</head><body>
<form id="form1" runat="server">
<div style=" width:500px;height:500px">
<div id="test1" class="cl1">
</div>
<script type="text/javascript">
var iframeW;
var iframeH;
iframeH = document.getElementById('test1').offsetHeight;
iframeW = document.getElementById('test1').offsetWidth;
alert(iframeH);
alert(iframeW);
</script>
</div>
</form>
</body>
</html>
.css文件中:
body {
}
.cl1
{
background-color:Black;
width:89%;
height:89%;
}不知道为什么 在IE中可以iframeH和iframeW的数据是正确的 但是用firefox的时候就出错了 我试了下 如果直接引用一个css的话 firefox也可以得到正确数据 但是 用 setActiveStyleSheet(test6);
function setActiveStyleSheet(title)
{
document.getElementsByTagName("link")[0].href=title;
}
这个方法引用css css文件的确被应用到网页上了 但是firefox读出来的div数据就会出错请各位大侠指点
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Sandbox_Professional_DashBoard_Default3" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function pageLoad() {
}
<!--
var test6 = "StyleSheet3.css";
setActiveStyleSheet(test6);
function setActiveStyleSheet(title)
{
document.getElementsByTagName("link")[0].href=title;
}
//-->
</script>
</head><body>
<form id="form1" runat="server">
<div style=" width:500px;height:500px">
<div id="test1" class="cl1">
</div>
<script type="text/javascript">
var iframeW;
var iframeH;
iframeH = document.getElementById('test1').offsetHeight;
iframeW = document.getElementById('test1').offsetWidth;
alert(iframeH);
alert(iframeW);
</script>
</div>
</form>
</body>
</html>
.css文件中:
body {
}
.cl1
{
background-color:Black;
width:89%;
height:89%;
}不知道为什么 在IE中可以iframeH和iframeW的数据是正确的 但是用firefox的时候就出错了 我试了下 如果直接引用一个css的话 firefox也可以得到正确数据 但是 用 setActiveStyleSheet(test6);
function setActiveStyleSheet(title)
{
document.getElementsByTagName("link")[0].href=title;
}
这个方法引用css css文件的确被应用到网页上了 但是firefox读出来的div数据就会出错请各位大侠指点
<head>
<link id="sheet1" href="css.css" rel="stylesheet" type="text/css"/>
<title>无标题页</title>
</head>
<body>
<div class="div"></div>
<input type="button" onclick="s.disabled=!s.disabled" value="测试"/>
<script type="text/javascript">
var s = document.getElementById("sheet1");
s.disabled = true;
</script>
</body>
</html>
测试用css.css文件
div{width:100px;height:100px;border:1px solid #000;background:red}
2。css文件尚未加载完成,你已经要打出长度了。
建议你下面的代码写在window.onload里,看效果。
路径这个我不大明白 不好意思 这方面新手
另外加载顺序应该是问题所在 我用<link href="StyleSheet3.css" rel="stylesheet" type="text/css" /> 就可以得到正确数据 但是 如果我用
<link href="" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function pageLoad() {
}
<!--
var test6 = "StyleSheet3.css";
setActiveStyleSheet(test6);
function setActiveStyleSheet(title)
{
document.getElementsByTagName("link")[0].href=title;
}
//-->
</script>
就不行 而且似乎第一个alter出来后才css 才加载上去的, 但是这个网页要根据不同分辨率读不同的css
IE是加载完成所有样式表再渲染 而 firefox是 边加载边渲染 我的问题是不是出在这里了呢 但是又不知道怎么解决 请各位大侠指点
var iframeW;
var iframeH;
iframeH = document.getElementById('test1').offsetHeight;
iframeW = document.getElementById('test1').offsetWidth;
alert(iframeH);
alert(iframeW);
</script>
将这段代码放在onload里执行看看
function abc() {
var iframeW;
var iframeH;
var iframeBG
iframeH = document.getElementById('iframe').offsetHeight;
iframeW = document.getElementById('iframe').offsetWidth;
}
加了个timer让firefox把css都读完 问题解决了 但是 我担心 这样如果用户的网速很慢 会影响结果
各位大侠 有没有什么方法 让firefox读完css再显示啊 谢谢