Javascript或jQuery中的Left()函数 [英] Left() function in Javascript or jQuery

查看:102
本文介绍了Javascript或jQuery中的Left()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想要一个非常方便的方法从Javascript中提取字符串中的数字,我正在考虑使用jQuery,但我更喜欢被证明是最简单的方法。我已经使用jQuery请求了一个css块的left属性:

I just want a very handy way to extract the numbers out of a string in Javascript and I am thinking about using jQuery, but I prefer the method that proves to be the simplest. I have requested the "left" attribute of a css block using jQuery like this:

var stuff = $('#block').css("left")

stuff的结果是

1008px

我只是我想摆脱px,因为我需要做一个parseInt。什么是最好的方法?如果Javascript有一个left()函数,这将非常简单。谢谢

I just want to get rid of the "px" because I need to do a parseInt of it. What is the best method? If Javascript had a left() function, this would be very simple. Thanks

推荐答案

只需做一个 parseInt(1008px,10) ,它会忽略'px'给你。

Just do a parseInt("1008px", 10), it will ignore the 'px' for you.

这篇关于Javascript或jQuery中的Left()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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