且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery min-width vs width:如何删除px?

更新时间:2023-02-05 22:41:30

使用 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