简体   繁体   English

jQuery具有窗口或文档的多个选择器

[英]jQuery multiple selectors with window or document

I know how to use multiple CSS selectors with jQuery, but how can I bind an event listener to multiple selectors when one of them is an object, the document or the window object for instance. 我知道如何在jQuery中使用多个CSS选择器,但是当其中一个是对象, documentwindow对象时,如何将事件侦听器绑定到多个选择器。

The following doesn't work : 以下不起作用:

$('html, body', document).scroll(function () {
    if(Screen.detectScroll() === 'down') {
        self.hide();
    } else {
        self.show();
    }
});

You can use jQuery's Add() to add selectors. 您可以使用jQuery的Add()来添加选择器。

$('html, body').add(document).scroll(function () {
    if(Screen.detectScroll() === 'down') {
        self.hide();
    } else {
        self.show();
    }
});

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

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