此方法用于在选择器的基础之上检查当前的元素是否含有某个特定的类,如果有,则返回true
实例:
<!DOCTYPE html> <html lang=‘zh-cn‘> <head> <title>Insert you title</title> <meta http-equiv=‘description‘ content=‘this is my page‘> <meta http-equiv=‘keywords‘ content=‘keyword1,keyword2,keyword3‘> <meta http-equiv=‘Content-Type‘ content=‘text/html; charset=utf-8‘> <script type=‘text/javascript‘ src=‘./js/jquery-1.12.1.min.js‘></script> <style type=‘text/css‘> </style> <script type=‘text/javascript‘> $(function(){ $(‘li‘).each(function(index){ if($(this).hasClass(‘hover‘)){ console.log($(this).html()); } }); }); </script> </head> <body> <div id=‘demo‘> <ul id=‘list‘> <li></li> <li></li> <li class=‘active hover‘>123</li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> </div> </body> </html>
时间: 2024-10-22 14:36:52