【问题标题】:Cannot query for disabled select elements无法查询禁用的选择元素
【发布时间】:2021-09-30 19:53:10
【问题描述】:

我可以选择所有未禁用但由于某种原因该方法不适用于选择元素的输入。

var inputs = document.querySelectorAll('input:not([disabled]), select:not([disabled])');

还有其他方法可以查询非禁用的 Selects 吗?我不能说 :not 选择器是否不起作用,或者是否有一些规则阻止选择器起作用。

感谢我们的回答 :)

【问题讨论】:

    标签: javascript select input queryselector


    【解决方案1】:

    您应该能够像在选择器中一样查询非禁用选择。包含问题的实际示例 (HTML) 可能表明您还有其他问题。

    document.querySelectorAll('input:not([disabled]),select:not([disabled])')
      .forEach(input => console.log(input.value));
    html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
    body { display: flex; flex-direction: column; justify-content: center; align-items: center; }
    <input type="text" value="found-input" />
    <input type="text" value="not-found-input" disabled />
    <select><option value="found-select" selected></option></select>
    <select disabled><option value="not-found-select" selected></option></select>

    【讨论】:

      猜你喜欢
      • 2021-10-21
      • 2020-02-08
      • 2021-09-17
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 2018-02-07
      • 2023-04-09
      • 2017-06-26
      相关资源
      最近更新 更多