借用jQuery的节目和隐藏

时间:2015-06-03 18:44:55

标签: javascript jquery

$('.foo').each(function () {
    var $this = $(this);
    var fooText = $this.text();
    var displayFunction = (fooText.toLowerCase().indexOf(filterText.toLowerCase()) != -1) ? $.show : $.hide;
    displayFunction.apply($this);
    displayFunction.apply($this.next());
}

看起来$ .show和$ .hide未定义,我该如何解决?

1 个答案:

答案 0 :(得分:6)

使用$.fn.show$.fn.hide

$的所有实例都继承了$.fn上定义的方法,这是jQuery原型的别名。或者,您可以使用$().hide,但不需要创建实例。

相关问题