<!doctype html><html> <head> <meta charset="utf-8"> <title>JS/Jquery复选框控制多个对应div的显隐</title> <script type="text/javascript" src="jquery-1.11.3.min.js"></script> </head> <style type="text/css"> .shows{ display: none; } </style> <body> <input type="checkbox" value="dd1" />淘宝<br /> <input type="checkbox" value="dd2" />新浪<br /> <input type="checkbox" value="dd3" />网易<br /> <input type="checkbox" value="dd4" />天猫<br /> <div id="dd1" class="shows">淘宝</div> <div id="dd2" class="shows">新浪</div> <div id="dd3" class="shows">网易</div> <div id="dd4" class="shows">天猫</div> <script type="text/javascript"> $(":checkbox").each(function () { $(this).click(function () { if ($(this).attr("checked") == "checked") { $("#" + $(this).val()).hide(); $(this).attr("checked",false); } else { $("#" + $(this).val()).show(); $(this).attr("checked",true); } }); }); </script> </body> </html>
______________
时间: 2024-10-09 19:57:49