我是Jquery新手,已经编写了一个toggle函数,看起来像这样:
$('.one-toggle').click(function(){
$('.one-graph').toggle();
});
基本上我想改变我的两个CSS选择器,使它们匹配任何标签,有一个开关和一个图形。我不希望选择器要求直接匹配。正则表达式可能吗?
使用标准的CSS选择符分隔符:
$('.one-toggle, .one-graph').click(function(){
$('.one-graph').toggle();
});
要匹配具有两个类名的标记,您只需要这样做:
// 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();
});