我正在尝试检测字符串是否为列表项样式...,我还有以下代码:
var test = "1. anything";
if( test[0] == /\d/ && test[1] == '.' ) { alert("it is list-item") }
但我从未见过alert()
。为什么?我希望看到该警报,因为该变量的第一个字符是数字,第二个字符是 .
.
最佳答案
这个怎么样
if (test.match(/^\d+\.*/) !== null) {
alert('it is list-item');
}
关于javascript - 如何实现条件中的任意数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35099204/