js使用正则表达式判断是否含有类选择器
时间: 2023-06-13 14:02:37 浏览: 100
可以使用以下正则表达式判断是否含有类选择器:
```javascript
/\.[\w-]+/
```
其中,`\.[\w-]+`用于匹配类选择器,`\w`表示匹配所有字母、数字和下划线,`-`表示匹配连字符。使用该正则表达式,如果匹配到类选择器,则返回true,否则返回false。例如:
```javascript
var str = "div.box p.text";
var hasClass = /\.[\w-]+/.test(str);
console.log(hasClass); // true
```
阅读全文
相关推荐
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)