jQuery min-width vs width:如何删除px? [英] jQuery min-width vs width: How to remove px?

查看:469
本文介绍了jQuery min-width vs width:如何删除px?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里尝试一些基本的jQuery和JavaScript。



.width()给出一个整数值。 .css('min-width')给我一个以 px 结尾的值。因此,我不能这样做数学。建议的工作是什么?

  alert($('#<%= lstProcessName.ClientID%>')。 parent('。column4')。width()); 
alert($('#<%= lstProcessName.ClientID%>')。parent('。column4')。css('min-width'));
alert($('#<%= lstProcessName.ClientID%>')。parent('。column4')。width()> = $('#<%= lstProcessName.ClientID%> ;')。parent('。column4')。css('min-width'));

if($('#<%= lstProcessName.ClientID%>')。parent('。column4')。width()> = $('#<%= lstProcessName .ClientID%>')。parent('。column4')。css('min-width')){
...
}
/ pre>

解决方案

使用 replace()

  alert($('#<%= lstProcessName.ClientID%>')。parent('。column4')。css -width')。replace('px','')); 

或者,您可以使用 parseInt 函数:

  alert(parseInt('1px')); // Result:1 


Trying some basic jQuery and JavaScript here.

The .width() gives me an integer value. The .css('min-width') gives me a value ending in px. Therefore I can't do math on this as is. What is the recommended work around?

alert($('#<%=lstProcessName.ClientID%>').parent('.column4').width());
alert($('#<%=lstProcessName.ClientID%>').parent('.column4').css('min-width'));
alert($('#<%=lstProcessName.ClientID%>').parent('.column4').width() >= $('#<%=lstProcessName.ClientID%>').parent('.column4').css('min-width'));

if ($('#<%=lstProcessName.ClientID%>').parent('.column4').width() >= $('#<%=lstProcessName.ClientID%>').parent('.column4').css('min-width')) {
  ...
}

解决方案

Use replace():

alert($('#<%=lstProcessName.ClientID%>').parent('.column4').css('min-width').replace('px', ''));

Alternatively, you could use the parseInt function:

alert(parseInt('1px')); //Result: 1

这篇关于jQuery min-width vs width:如何删除px?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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