Select 没有确定的按钮元素 类
Select a button element without certain classes
我的网页中有一个按钮。这个按钮我想要class"btn-default",但我不想每次都写出来。我怎样才能使用 jQuery 给每个没有 classes 的按钮:"btn-warning btn-primary btn-danger" "btn-default" class?
jQuery 选择器
:not() 选择器是 jQuery!
中的一个很棒的工具
$('button:not(.btn-primary, .btn-warning, .btn-danger)').addClass('btn-default');
使用 .not() 函数
$('button').not('.btn-primary, .btn-warning, .btn-danger').addClass('btn-default').css('background-color', 'blue');
您可以使用 jquery 来捕获页面上的每个按钮,使用
$( ":button" )
然后检查它是否有特定的 class 使用:
$( ":button" ).hasClass( "foo" )
如果没有你可以添加你自己的class
$( ":button" ).addClass( "foo" )
我的网页中有一个按钮。这个按钮我想要class"btn-default",但我不想每次都写出来。我怎样才能使用 jQuery 给每个没有 classes 的按钮:"btn-warning btn-primary btn-danger" "btn-default" class?
jQuery 选择器
:not() 选择器是 jQuery!
中的一个很棒的工具$('button:not(.btn-primary, .btn-warning, .btn-danger)').addClass('btn-default');
使用 .not() 函数
$('button').not('.btn-primary, .btn-warning, .btn-danger').addClass('btn-default').css('background-color', 'blue');
您可以使用 jquery 来捕获页面上的每个按钮,使用
$( ":button" )
然后检查它是否有特定的 class 使用:
$( ":button" ).hasClass( "foo" )
如果没有你可以添加你自己的class
$( ":button" ).addClass( "foo" )