获取一个表单内的输入框,单选框,复选框等元素有哪些被display隐藏
时间: 2023-11-28 08:47:25 浏览: 36
获取一个表单内的被 display 隐藏的元素有以下几种方式:
1. 使用 JavaScript 的 `querySelectorAll` 方法,结合 CSS 选择器来获取所有被隐藏的元素,例如:
```
var hiddenElements = document.querySelectorAll('input[type="hidden"], input[type="checkbox"][hidden], input[type="radio"][hidden], select[hidden], textarea[hidden]');
```
2. 使用 jQuery 库中的 `:hidden` 伪类选择器,例如:
```
var hiddenElements = $('input[type="hidden"], input[type="checkbox"]:hidden, input[type="radio"]:hidden, select:hidden, textarea:hidden');
```
3. 使用 CSS 中的 `:not(:visible)` 伪类选择器,例如:
```
var hiddenElements = document.querySelectorAll('input[type="hidden"], input[type="checkbox"]:not(:visible), input[type="radio"]:not(:visible), select:not(:visible), textarea:not(:visible)');
```
这些方法都可以获取表单中被 display 隐藏的元素,包括输入框、单选框、复选框等。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)