运行 ❯
获取你
自己的
网站
×
更改方向
保存代码
更改主题,暗色/亮色
前往 Spaces
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").filter(function(){ return $("span", this).length == 2;}).css("background-color", "yellow"); }); </script> </head> <body> <div> <p>A p element <span>with one span element.</span></p> <p>A p element <span>with</span> two <span>span elements.</span></p> <p>A p element <span>with one span element.</span></p> <p>A p element <span>with</span> two <span>span elements.</span></p> <p>A p element with no span element.</p> </div> <p>This example returns all p elements that have two span elements. P elements with none, one, or more than two span elements, will not be returned.</p> </body> </html>