children([selector])方法获取一组元素,其中包含每个匹配元素集的所有唯一直接子代。
selector.children( [selector] )
这是此方法使用的所有参数的描述-
selector - 这是一个可选参数,用于过滤所有子项。如果未提供,则将选择所有子项。
以下是一个简单的示例,简单说明了此方法的用法-
<html> <head> <title>The jQuery Example</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script> $(document).ready(function(){ $("div").children(".selected").addClass("blue"); }); </script> <style> .blue { color:blue; } </style> </head> <body> <div> <span>Hello</span> <p class="selected">Hello Again</p> <div class="selected">And Again</div> <p class="biggest">And One Last Time</p> </div> </body> </html>
这会将蓝色应用于每个div类别为" selected"的所有子级,如下所示-
HelloHello Again
And AgainAnd One Last Time
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Cloud 微服务项目实战 -〔姚秋辰(姚半仙)〕