新浪微博 登陆  注册   设为首页 加入收藏

问题 2012-02-10 05:16:27     点击:48967

[JS&JQUERY] jquery如何获取DIV里CSS设置是百分比的宽度呢?

$("#JS_top_ment").width()

如果是百分比的时候这个参数会是null的

如果是$("#JS_top_ment").css("width")的话,就会显示undefined

如果写法是$("#JS_top_ment").atrr("width")这就是错误的~什么也没有显示出来~

那请问如何才能获取他的宽度呢?

要求:准确数值,因为我还需要那个数值做个判断喔~








推荐答案   2012-02-10 05:16:27

$("#JS_top_ment").css("width","60%")

jquery的CSS格式为("属性","参数")

如果要获取width的百分比输入以下代码就可以了

Math.round(($("#JS_top_ment").width()/$(document).width())*100)









1楼 Daniel说: 2013-04-14 23:59:58
I just hope whevoer writes these keeps writing more!
2楼 Lyddy说: 2016-12-21 14:22:08
I simply had to thank you very much all over again. I’m not certain the things that I could possibly have carried out in the absence of these tactics discussed by you on that theme. It seemed to be a very daunting problem in my position, but finding out your specialised way you solved the issue forced me to weep with happiness. Extremely happier for your guidance and expect you really know what an amazing job that yor7u821&;#e undertaking teaching some other people via a web site. I am sure you’ve never got to know any of us.



  发表评论
昵称:
(不超过20个字符或10个汉字)

内容: