我是新的Jquery并编写了一个切换函数,如下所示:
$('.one-toggle').click(function(){
$('.one-graph').toggle();
});
基本上我想改变我的两个CSS选择器,以便它们匹配任何具有一个切换和一个图形的标签。我不希望选择器需要直接匹配。可能是正则表达式?
答案 0 :(得分:1)
只需使用标准的CSS选择器分隔符:
$('.one-toggle, .one-graph').click(function(){
$('.one-graph').toggle();
});
答案 1 :(得分:0)
要匹配具有两个类名的标签,您只需要:
// cache the selector
var $elements = $('.one-toggle.one-graph').click(function(){
// toggle all matched elements
$elements.toggle();
// or did you want to toggle just the clicked element?
// $(this).toggle();
});