duanjiu1950
2013-10-14 20:16
浏览 110

在CSS中选择具有相同父项的多个子项

I'm using PHPQuery, which is a PHP port of jQuery, so it also uses CSS selectors. However, one difference is that PHPQuery does not return matched elements in the document order when there are multiple selectors.

Is it possible to combine this into one selector?

#article>p,#article>blockquote

The only other solution I can think of is:

#article>*:not(div):not(table):not(ul):not(...

图片转代码服务由CSDN问答提供 功能建议

我正在使用PHPQuery,它是jQuery的PHP端口,所以它也使用CSS选择器。 但是,有一个区别是,当有多个选择器时,PHPQuery不会按文档顺序返回匹配的元素。

是否可以将它组合成一个选择器? \ n

 #article> p,#article> blockquote 
   
 
 

我能想到的唯一其他解决方案是: \ n

 #article> *:not(div):not(table):not(ul):not(... 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongre6404 2013-10-14 21:39
    已采纳

    I haven't used phpQuery(till 5 minutes ago) but as it works like jQuery, using it's .filter() method should do the trick, the idea is selecting all the children and then filtering the elements that match the criteria.

    $doc['#article']->children()->filter(function($i, $element) {
        return in_array($element->tagName, array('blockquote', 'p'));
    })->foo();
    
    点赞 评论
  • dongtingrun4973 2013-10-14 20:18

    You can combine the selector use add()

    $('#article>p').add('#article>blockquote')
    

    Given a jQuery object that represents a set of DOM elements, the .add() method constructs a new jQuery object from the union of those elements and the ones passed into the method. The argument to .add() can be pretty much anything that $() accepts, including a jQuery selector expression, references to DOM elements, or an HTML snippet, jQuery api.

    点赞 评论

相关推荐 更多相似问题