如何使用jQuery以百分比形式获得div的宽度? [英] How to get width of a div in percentage using jQuery?
本文介绍了如何使用jQuery以百分比形式获得div的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个div,我想知道是否有一种使用jQuery来获取其宽度百分比的方法.
I have a div, and I'd like to know if there's a way to get its width in percentage using jQuery.
这是我的代码:
$(document).ready(function(){
var f = $('.f').width();
alert(f);
});
我试图使用%
作为这样的参数,例如width(%)
,但这是将宽度设置为%
,但没有以百分比格式获取值.有人可以告诉我该怎么做才能获得百分比吗?
I tried to use %
as an argument like this width(%)
, but this is setting the width as %
not getting the value in a percentage format. Can someone tell me what should I do to get in percentage instead?
任何帮助都将受到感激.
Any help is profusely appreciated.
推荐答案
使用示例代码...
$(document).ready(function(){
var f = $(".f").width() / $('.f').parent().width() * 100;
alert(f);
});
这篇关于如何使用jQuery以百分比形式获得div的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文