javascript - 在javascript中获取子字符串并转换为整数
问题描述
const [top, bottom, left, right] = [txtStyle.getPropertyValue('top'),
txtStyle.getPropertyValue('bottom'),
txtStyle.getPropertyValue('left'),
txtStyle.getPropertyValue('right')];
值被分配为“24px”等。但我想将其分配为 24(int)。最好的方法是什么?
解决方案
您可以使用parseInt
const [top, bottom, left, right] = [parseInt(txtStyle.getPropertyValue('top')),
parseInt(txtStyle.getPropertyValue('bottom')),
parseInt(txtStyle.getPropertyValue('left')),
parseInt(txtStyle.getPropertyValue('right'))
];
推荐阅读
- css - 以增量重复背景
- c++ - 为什么 STL 的 Map 中的值没有变化?
- android - 谷歌地图卫星视图 - 改变亮度或对比度?
- javascript - 如何纠正谷歌浏览器扩展中的内联脚本问题
- xamarin.ios - ios 应用程序的团队配置与临时配置
- python - 如何加速 pyspark 的计算
- dialogflow-es - Intent Capture and Authenticate (Intents 和 Calling Webhook 的设计)
- php - 多次上传文件不保存
- php - 如何解决这个错误“[ErrorException] count(): Parameter must be an array or an object that implement Countable”?
- r - 如何创建自定义 Shinydashboard 皮肤