Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/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文件的宽度百分比_Jquery_Html - Fatal编程技术网

如何使用jquery检测css文件的宽度百分比

如何使用jquery检测css文件的宽度百分比,jquery,html,Jquery,Html,我希望使用jquery从css文件中获取宽度,但使用此方法时: $('element').width()获取像素大小元素,但在css文件中,此元素的大小百分比为 如何得到它。 html: <div id="content"></div> 为了无聊: var mywidth = $('#content').width(), parentwidth = $('#content').parent().width(), percentagewidth = (my

我希望使用jquery从css文件中获取宽度,但使用此方法时:

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

如何得到它。 html:

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

为了无聊:

var mywidth = $('#content').width(),
    parentwidth = $('#content').parent().width(),
    percentagewidth = (mywidth*100)/parentwidth;
    alert(precentagewidth+"%");
==将数字四舍五入==

Math.round(precentagewidth)

文档。

您需要阅读CSS文件本身。虽然可以通过
element.style.width
检索
style=“width:50%”
,但对于样式表内容,您不能执行相同的操作。我如何读取css文件并检索我朋友的此可能重复项如何舍入此值???(我做了,但得到了这个19.8465467897465456%)我想得到20%,那么如何取整呢?@mohammad编辑了答案:)希望这就是你想要的need@mohammad如果答案解决了你的问题,请接受它
Math.round(precentagewidth)