prevAll([selector])方法查找当前元素前面的所有同级元素。
selector.prevAll( [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 type = "text/javascript" language = "javascript"> $(document).ready(function(){ $("div:last").prevAll().addClass("hilight"); }); </script> <style> .hilight { background:yellow; } </style> </head> <body> <div>first</div> <div>sibling<div>child</div></div> <div>sibling</div> <div>sibling</div> </body> </html>
这将产生以下输出-
firstsiblingchildsiblingsibling
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)