Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery css(';top';)和IE8_Jquery_Css_Internet Explorer 8_Styles - Fatal编程技术网

Jquery css(';top';)和IE8

Jquery css(';top';)和IE8,jquery,css,internet-explorer-8,styles,Jquery,Css,Internet Explorer 8,Styles,我对IE8+jQuery.css('top')函数有问题 1) 我有一个高100像素,宽600像素的DIV。我在第一个DIV中有另一个DIV,style=“top:50%”,所以它应该放在top=50px 2) 所有浏览器都能正确显示它。但是,稍后,我需要使用jQuery查找元素的位置,IE8的问题来了: $('#txt').css('top')返回的不是50px而是300px!!!!!这是不正确的。我还注意到它总是返回父DIV的宽度为0.5*的值!!这让我发疯!怎么可能呢 下面是代码示例: &

我对IE8+jQuery.css('top')函数有问题

1) 我有一个高100像素,宽600像素的DIV。我在第一个DIV中有另一个DIV,style=“top:50%”,所以它应该放在top=50px

2) 所有浏览器都能正确显示它。但是,稍后,我需要使用jQuery查找元素的位置,IE8的问题来了:

$('#txt').css('top')返回的不是50px而是300px!!!!!这是不正确的。我还注意到它总是返回父DIV的宽度为0.5*的值!!这让我发疯!怎么可能呢

下面是代码示例:

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>demo</title>

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript">            
        function onLoadTest(){
            alert("document.getElementById('txt').style.top="+document.getElementById('txt').style.top+"\n$(#txt).css('top')="+$('#txt').css('top'));
        }
    </script>

</head>
<body onload="onLoadTest()" style="padding: 0px; margin: 0px; width:100%; height:100%">             
    <div id="box" style="width:600px; height:100px; position:absolute; padding:0px; margin:0px; border: solid 1px">
        <div id="txt" style="top:50%; position:relative; padding:0px; margin:0px;border: solid 1px">
            im in the position top=50% (which is 50px), plz compare to alert box data
        </div>          
    </div>  
</body>
</html>

演示
函数onload测试(){
警报(“document.getElementById('txt').style.top=“+document.getElementById('txt').style.top+”\n$(#txt.css('top')=”+$('#txt').css('top'));
}
im在位置top=50%(即50px),plz与报警框数据比较
这是我的。尝试使用offset()。有时绝对的感觉会很奇怪。 使用偏移量是与寄宿者对你的父母将得到你51,所以我把寄宿者从父母