Comma separated list of selectors?

前端 未结 4 1026
一向
一向 2020-12-15 17:59

I\'m refactoring some code at the moment and have come across a selector:

jQuery(\"tr\",\"#ctl00_MainContent_MyUserControl\").each(function(i,row) { ... }
         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-15 18:22

    Calling the jQuery() method with two arguments (selector and context) is equivalent to jQuery(context).find(selector). Thus:

    jQuery("tr","#ctl00_MainContent_MyUserControl");
    

    is equal to:

    jQuery("#ctl00_MainContent_MyUserControl").find("tr");
    

    which also happens to be the same as:

    jQuery("#ctl00_MainContent_MyUserControl tr");
    

    My personal opinion is that the use of context only makes sense when you can pass an already selected element (jQuery or DOM), not so much when you just pass a selector (String). In that case I simply prefer to mimic the CSS selector: e.g., #ctl00_MainContent_MyUserControl tr.

提交回复
热议问题