Javascript如何添加style =&#34; display:none&#34;通过检查<li>内联样式来<div>?

时间:2015-10-17 05:52:13

标签: javascript

通过检查style="display:none"内嵌样式,Javascript检查如何将<div>添加到<li>

  • 根据上述代码,默认情况下所有<li>都有style="display:none"
  • 现在我希望javascript应该将所有<li>检查为style="display:none"
  • 如果所有<li>的{​​{1}} style="display:none"食物也会呈现为<div>食物

&#13;
&#13;
<div style="display:none">
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

这样的东西?

var allHidden = true;
$("#food ul li").each(function(){
    if($(this).is(":visible")){
        allHidden = false;
    }
});

if(allHidden){
   $("#food").hide();       
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="food"> Food <!-- Main Category -->

	<ul> 
		<li style="display:none"> Pizza </li>				<!-- Category Child Item -->
		<li style="display:none"> Falafel </li>				<!-- Category Child Item -->
		<li style="display:none"> Donuts </li>				<!-- Category Child Item -->
		<li style="display:none"> Burger </li>				<!-- Category Child Item -->
		<li style="display:none"> Cheese Sandwich </li>		<!-- Category Child Item -->
	</ul>

</div>

答案 1 :(得分:0)

由于没有function instate(loc) { var a; var geocoder = new google.maps.Geocoder; var infowindow = new google.maps.InfoWindow geocoder.geocode({'location': loc}, function(results, status) { if (status === google.maps.GeocoderStatus.OK) { if (results[1]) { map.setZoom(5); var arrAddress = results[0].address_components; $.each(arrAddress, function (i, address_component) { if (address_component.types[0] == "administrative_area_level_1"){ a = address_component.short_name; } //return false; // break the loop }); } else { window.alert('No results found'); } } else { window.alert('Geocoder failed due to: ' + status); } }); console.log(a); } 标记,我在本机Javascript中为@bhargavponnapalli解决方案提供了不同的内容:

jquery

以下是fiddle