想要截取字符串前几位与后几位,主要代码如下 截取字符串前几位 var disName ='开心一族漂亮家园'; var shortName = disName.substring(0,5); console.log(shortName);//打印结果:开心一族漂 截取字符串后几位 var disName ='开心一族漂亮家园'; var disLength = disName.length; var shortName = disName.substring(disLength-2,disLen…
例子1: var num = "112233.99887766";console.log(num.substring(0,(num.indexOf(".")+5)));返回:112233.9988 例子2: var item = "https://www.oss-cn-hangzhou.aliyuncs.com/www20190107/e220d0f66c8a643c8e16dc9aa01f51b3194/箱数.png";console.log(…