读书人

jquery的height()方法在chrome中无法正

发布时间: 2012-05-28 17:59:33 作者: rapoo

jquery的height()方法在chrome中无法正常工作

JScript code
jQuery.fn.gallery = function(){        return this.each(function(){            var e = $(this);            var h = e.height();            e.height(128);            e.click(function(){                //show big preview                e.clone().height(h).prependTo("body");            })        })    }

这段代码的中h取得的e元素的高度在chrome浏览器中始终为0,但是在firefox里面正常显示
怎么解决这个问题啊?求高手指教,我用的jquery-1.7.2.js
e表示的是一个img元素,高度600px

[解决办法]
需要等资源加载完毕

HTML code
<!DOCTYPE HTML><html>    <head>        <meta charset="gb2312" />        <title></title>                <script src="http://code.jquery.com/jquery-latest.js"></script>        <style>                </style>    </head>    <body>        <img src="http://avatar.profile.csdn.net/1/7/A/2_prettywhitewolf_xiao.jpg">        <script>jQuery.fn.gallery = function(){        return this.each(function(){            var e = $(this);            var h = e.height();            e.height(128);            e.click(function(){                //show big preview                e.clone().height(h).prependTo("body");            })        })    }    window.onload = function(){        $('img').gallery()    }        </script>    </body></html> 

读书人网 >JavaScript

热点推荐