可以使用 querySelector 查找具有不确定状态设置的 HTML 输入吗?

huangapple go评论55阅读模式
英文:

Can HTML inputs with an indeterminate state set be found via querySelector?

问题

有没有一种方法可以启用这个功能?或者它是在CSS的范围之外进行管理的?
我认为根据我目前的研究和它没有作为“input”上的属性呈现的事实,目前似乎没有办法。

英文:

Is there a method to enable this? Or is it managed beyond the reach of CSS?

I'm thinking there's no way based on my research so far and the fact it's not rendered as an attribute on the input.

答案1

得分: 3

有一个 :indeterminate 伪类。

const inp = document.querySelector("input");
inp.indeterminate = true;
:indeterminate { outline: 5px solid red; }
<input type="checkbox">
<input type="checkbox">
英文:

There is an :indeterminate pseudo class.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const inp = document.querySelector(&quot;input&quot;);
inp.indeterminate = true;

<!-- language: lang-css -->

:indeterminate { outline: 5px solid red; }

<!-- language: lang-html -->

&lt;input type=&quot;checkbox&quot;&gt;
&lt;input type=&quot;checkbox&quot;&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月16日 09:53:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76486511.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定