javascript-如何在querySelector中实现`not`? [英] javascript - how to implement `not` in querySelector?

查看:554
本文介绍了javascript-如何在querySelector中实现`not`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速问题:
假设您有2种不同的< button>

第一个看起来像这样: < button class = test>

秒看起来像这样:< button class = test disable = disabled>

现在,如何在不选择的情况下实现对禁用按钮的选择已激活按钮?原因是如果您按班级去做, querySelector 会同时获得它们。是否可以在 querySelector 进行的选择中实现某种逻辑?

Now, how can one achieve a selection of the disabled button without selecting the activated button? Cause if you go by class, querySelector would get both of them. Is there a way to implement some kind of logic into the selection made by querySelector?

类似这样的东西-> 带有测试类而不是禁用属性的选择按钮

Something like this maybe -> "select button with class 'test' AND NOT attribute 'disabled'"?

预先感谢。

推荐答案

与您相同的操作方式在任何其他选择器中。使用否定伪类

The same way you do it in any other selector. With the negation pseudo-class.

:not([disabled])

这篇关于javascript-如何在querySelector中实现`not`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆