简体   繁体   English

如何使用ID阻止特定选择器上的CSS / JavaScript?

[英]How to prevent CSS/JavaScript on specific selectors using Id?

I am using this JavaScript to add CSS class on radio buttons and checkbox in my code. 我正在使用此JavaScript在我的代码中的单选按钮和复选框上添加CSS类。

    $('input[type="checkbox"]').iCheck({
        checkboxClass: 'icheckbox_flat-blue'
    });
    $('input[type="radio"]').iCheck({
        radioClass: 'iradio_flat-blue'
    });

I am following layout and content phenomenon in my HTML pages in other words I have one layout.html which contains all the sections and divisions which are similar in all pages and I use this layout in my content.html pages to render content. 我正在跟踪HTML页面中的布局和内容现象,换句话说,我有一个layout.html,其中包含所有页面中都相似的所有部分和分区,并且我在content.html页面中使用此布局来呈现内容。

|----------------------|                      |----------------------|
|   Header             |                      |   Header             |
|======================|                      |======================|
|                      |                      |                      |
|                      |                      |                      |
|     Content 1        |                      |    Content xyz       |
|                      |                      |                      |
|                      |                      |                      |
|======================|                      |======================|   
| footer               |<-----Layout--------->| footer               | 
|----------------------|                      |----------------------|

All CSS and Scripts are in layout as I am using them in almost every content page. 所有CSS和脚本都在布局中,因为我几乎在每个内容页面中都在使用它们。 My content pages contain HTML input fields like text, radio etc. The above script is in layout file which adds CSS class in radio buttons and check-boxes in my content pages. 我的内容页面包含HTML输入字段,例如文本,单选等。以上脚本位于布局文件中,该文件在我的内容页面的单选按钮和复选框中添加了CSS类。 But their are certain places in the same content page where I don't want this script to work on my input fields. 但是它们是同一内容页面中的某些位置,我不希望此脚本在我的输入字段上工作。 I want to prevent this script on two radio buttons in the same content page where it is being used on other radio buttons. 我想在同一内容页面上的两个单选按钮上禁止使用此脚本,而在其他单选按钮上使用此脚本。 Is there any way to do this by giving an id to them? 有没有办法通过给他们一个ID来做到这一点?

You can set a class in the input radio you don't want to change: 您可以在不想更改的输入广播中设置班级:

<input type="radio" class="not-apply" />

And use the not operation in the jQuery selector: 并在jQuery选择器中使用not操作:

$('input[type="checkbox"]:not(.not-apply)')

If you are not using jQuery, and only pure javascript and css you can use this syntax 如果您不使用jQuery,而仅使用纯JavaScript和CSS,则可以使用此语法

document.querySelectorAll('span.test:not(.asd)');

CSS NOT CSS不

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM