Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.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
Javascript Chrome 30和类型显示元素的宽度:表格单元格?_Javascript_Jquery_Css_Google Chrome - Fatal编程技术网

Javascript Chrome 30和类型显示元素的宽度:表格单元格?

Javascript Chrome 30和类型显示元素的宽度:表格单元格?,javascript,jquery,css,google-chrome,Javascript,Jquery,Css,Google Chrome,我在使用最新的Chrome测试版(30.0.1599.14测试版)时遇到问题 我无法计算类型为display:table cell的元素的真实宽度 以下是一些测试代码,在调整浏览器窗口的大小时将表格单元格的宽度输出到控制台: <!DOCTYPE html> <html lang="en"> <head> <style> .table { background: #ffc;

我在使用最新的Chrome测试版(30.0.1599.14测试版)时遇到问题

我无法计算类型为display:table cell的元素的真实宽度

以下是一些测试代码,在调整浏览器窗口的大小时将表格单元格的宽度输出到控制台:

<!DOCTYPE html>
<html lang="en">

<head>        
    <style>
        .table {
            background: #ffc;
            display: table;
            width: 100%;
        }
        .cell {
            display: table-cell;
            width: 200px;
            border: 1px solid black;
            background: #ff0;
            height: 30px;
        }
        #testCell {
            background: #f00;
        }
    </style>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script>
        $(document).on( "ready", function() {
            $(window).on( "resize", function() {
                var width = document.getElementById( "testCell" ).offsetWidth;
                // non jQuery way, for testing:
                // var width = document.getElementById( "testCell" ).offsetWidth;
                console.log( width );
            });
        });
    </script>

</head>

<body>

    <div class="table">
            <div class="cell" id="testCell"></div>
            <div class="cell"></div>
            <div class="cell"></div>
            <div class="cell"></div>
            <div class="cell" ></div>
    </div>

</body>

</html>
…会完成任务的。不过,如果有人知道,我仍然有兴趣知道这里发生了什么


谢谢

我也有类似的问题

我认为问题在于Chrome30的回归


这里有另一篇关于这一点的帖子:

如果你试图用纯js复制它,而不使用jQ呢?只是在没有jQ的情况下尝试了一下——同样的问题。问题编辑。Thnx.您是否考虑过使用
style.width
而不是
offsetwidth
?@RUJordan-刚刚尝试过。它似乎也不起作用。事实上,它毫无价值。。这是一个测试版。。这可能就是问题所在。
var width = document.getElementById( "testCell" ).clientWidth;