繁体   English   中英

如何使用jQuery在CSS文件中检测百分比宽度

[英]how to detect percent width in css file with jquery

我想用jQuery从CSS文件中获取宽度,但是当使用这种方法时:

$('element').width() $('element').css('width'); 获取像素大小元素,但在css文件中此元素具有百分比大小....

如何获得它。 html:

<div id="content"></div>

的CSS

#content{width:50%}

为了无聊:

var mywidth = $('#content').width(),
    parentwidth = $('#content').parent().width(),
    percentagewidth = (mywidth*100)/parentwidth;
    alert(precentagewidth+"%");

==四舍五入==

Math.round(precentagewidth)

Math.round()文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM