标签:document 正则表达 fine info sub http mil htm inner
js怎么截取两个中括号中间的值,微秒有时两位有时三位,正则表达式也可以
[00:02.02],[00:02.342],[00:03.2],[00:03.42],[00:04.02],[00:05.342]
<body> <p id="demo"></p> <script> function getStr(str) { if (str == "" || str == null || str == undefined) { // "",null,undefined return ""; } var subArr = str.split(‘,‘); var str = ""; var strTemp = ""; for (var num = 0; num < subArr.length; num++) { console.log(subArr[num]); strTemp = subArr[num].substr(1, subArr[num].length); strTemp = strTemp.substr(0, subArr[num].length - 2) str += strTemp+","; //console.log(strTemp); } return str; } document.getElementById("demo").innerHTML = getStr("[00:02.02],[00:02.342],[00:03.2],[00:03.42],[00:04.02],[00:05.342]"); </script> </body>
标签:document 正则表达 fine info sub http mil htm inner
原文地址:https://www.cnblogs.com/shenbing/p/13776327.html