如何使用jquery获得我在CSS类中给出的百分比宽度百分比 [英] How can I get width in percentage which I have given in percentage in CSS class using jquery

查看:137
本文介绍了如何使用jquery获得我在CSS类中给出的百分比宽度百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..我有一个css类是.xyz。在这个类中,我有%的设置宽度属性。所以我的代码是

.xyz {width:3%}

我想要使用jquery的百分比相同的宽度。我到目前为止尝试了以下方法。 />
有没有什么方法可以直接获得我设置的相同宽度。



让我更清楚输出:我想要输出宽度为3%。



我尝试过:



1.

var f1 = $(。xyz)。width()/ $('。xyz')。parent()。width()* 100;

提醒(f1);



但是我得到输出宽度4.179797.

2.

alert($(。xyz)。css('width'));



我得到的输出是像素(px)

3.

alert($(。xyz)。width());

Hi.. I have one css class which is ".xyz" . In this class i have setup width property in "%". So my code is
.xyz {width:3%}
I want the same width which is in percentage using jquery.I have tried following ways so far.
Is there any way by which i can directly get the same width which i have setup.

Let me be more clear about output: I want width in output which is 3%.

What I have tried:

1.
var f1 = $(".xyz").width() / $('.xyz').parent().width() * 100;
alert(f1);

But by this i am getting output width 4.179797.
2.
alert($(".xyz").css('width'));

Output i got is in pixel("px")
3.
alert($(".xyz").width());

推荐答案

(。 xyz)。width()/
(".xyz").width() /


('。xyz')。parent()。width()* 100;

alert(f1);



但是我得到输出宽度4.179797.

2.

ale rt(
('.xyz').parent().width() * 100;
alert(f1);

But by this i am getting output width 4.179797.
2.
alert(


(。xyz)。css('width'));



我得到的输出是像素(px)

3.

alert(
(".xyz").css('width'));

Output i got is in pixel("px")
3.
alert(


这篇关于如何使用jquery获得我在CSS类中给出的百分比宽度百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆