日期:2014-05-16 浏览次数:20320 次
<div class="div1"><div> <div class="div2"><div> <div class="div3"><div>
$(document).ready(function(){ })
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ if($(".div1:visible,.div2:visible").length>0){ $(".div3").show(); }else{ $(".div3").hide(); } }); </script> </head> <body> <div class="div1" style="display:none;">1111</div> <div class="div2" style="display:none;">2222</div> <div class="div3">3333</div> </body> </html>
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style type="text/css"> div { width:200px; height:100px; background-color:#EEE; border:1px solid #999; margin-top:20px; } .div1, .div2 { display:none; } </style> <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script> <script type="text/javascript"> $(document).ready( function() { var len = $(".div1:hidden, .div2:hidden").length; if (len == 1) $(".div3").show(); else if (len == 2) $(".div3").hide(); }); </script> </head> <body> <div class="div1">DIV1</div> <div class="div2">DIV2</div> <div class="div3">DIV3</div> </body> </html>