简单小例子 (是否可见)(tab切换)
<html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script type="text/javascript"> function ff(){ $("#div").hide(); } function mm(){ alert($("#div").is(":visible")); } </script> </head> <body> <div id="div">sdf</div> <input type="button" value="点我" onclick="ff()" /> <input type="button" value="状态" onclick="mm()" /> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> * { margin: 0; padding: 0; } .d1 { /* 最大容器 */ width: 980px; margin: 100px auto; } .tab_list { height: 39px; border: 1px solid #ccc; background-color: #f1f1f1; } li { list-style-type: none; } .tab_list li { float: left; height: 39px; line-height: 39px; padding: 0 20px; text-align: center; cursor: pointer; } .tab_list .current { background-color: #c81623; color: #fff; } .item { display: none; } a { text-decoration: none; font-size: 30px; } </style> <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script> $(function () { $('.tab_list li').click(function () { $(this).addClass("current").siblings().removeClass("current"); var idx = $(this).index(); $('.tab_con .item').eq(idx).show().siblings().hide(); }); }) </script> </head> <body> <div class='d1'> <div class='tab_list'> <ul> <li class='current'>tab1</li> <li>tab2</li> </ul> </div> <div class="tab_con"> <div class="item" style="display: block;"> content1 </div> <div class="item"> content2 </div> </div> </body> </html>