不正确的 :not() 选择器语法

问题描述 投票:0回答:1

我试图选择元素

#manage-company
内既没有类
.partner
也没有
.representative-input
类的所有输入字段,然后操作它们的类。我尝试使用下面的行来完成此操作,但我认为我的选择语法不正确。

$('#manage-company input :not(.representative-input, .partner)').removeClass('form-control').addClass('form-control-plaintext');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<form id="manage-company">
    <input type="text" class="form-control" id="manage-company-name">
    <input type="text" class="form-control" id="manage-company-stateRegistration">

    <div id="manage-company-representativesList">
        <input type="text" class="form-control representative-input">

        <input type="email" class="form-control representative-input">
    </div>

    <div id="manage-company-partnersList">
        <input type="text" class="form-control partner">
    </div>
</form>

html jquery
1个回答
-2
投票

只需删除

input
:not
之间的空格,如下所示:

$('#manage-company input:not(.representative-input, .partner)').removeClass('form-control').addClass('form-control-plaintext');
.form-control-plaintext {
  background-color: green;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<form id="manage-company">
    <input type="text" class="form-control" id="manage-company-name">
    <input type="text" class="form-control" id="manage-company-stateRegistration">

    <div id="manage-company-representativesList">
        <input type="text" class="form-control representative-input">

        <input type="email" class="form-control representative-input">
    </div>

    <div id="manage-company-partnersList">
        <input type="text" class="form-control partner">
    </div>
</form>

© www.soinside.com 2019 - 2024. All rights reserved.