Home  >  Article  >  Web Front-end  >  When setting the display and shadowing of images, my code does not work when clicked. What's going on? _html/css_WEB-ITnose

When setting the display and shadowing of images, my code does not work when clicked. What's going on? _html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:57:35803browse

a97480cf758b0ed64de3a1ed4a066dcf
.childeMenu{display:none;list-style:none;}
531ac245ce3e4fe3d50054a55f265927
9bc988c8d379612a3b235e5490d962db
function show(id){
var ul=document.getElementById("id");
if(ul.style.display=="block"){
ul.style.display="none";
}else{
ul.style.display="block";
}
}
2cacc6d41bbb37262a98f745aa00fbf0
9c3bca370b5104690d9ef395f2c5f8d1
6c04bd5ca3fcae76e30b72ad730ca86d
a4b561c25d9afb9ac8dc4d70affff4199763126a8d2d410570c64d6dbf822d6e树形菜单:0d36329ec37a2cc24d42c7229b69747a
91c6107534735594166ce5a7d6d95299
a4b561c25d9afb9ac8dc4d70affff419b18e59b791c43cca6a989749011bed56acb5ca144c5a7ea3975508795adba89e文学艺术5db79b134e9f6b82c0b36e0489ee08ed0d36329ec37a2cc24d42c7229b69747a
ab8595e3a45bd3dc1b6c9fa4ce846601
  25edfb22a4f469ecb59f1190150159c60e3c79ff215b81ac25ec687830707064先锋bed06894275b65c1ab86501b08a632eb
    25edfb22a4f469ecb59f1190150159c6cbba1a94f713e3c385f88a805ee42aae感恩bed06894275b65c1ab86501b08a632eb
929d1f5ca49e04fdcb27f9465b944689


回复讨论(解决方案)

改成
var ul=document.getElementById("art");

你没有id="id"的元素

赞同楼上

赞同楼上

你没有给show传id参数

你要使用参数,你需要这样写
var ul=document.getElementById(id);


1c0e569045a736648040a8c345f896f6

 <script src="jquery-1.9.1.js"></script>	  <script>	  	 $(function () {	  	 	 $("#displayShow").click(function () {	  	 	 	 if ($("#art").hide())//可以改成$(".childeMenu").hide()	  	 	 	 	 $("#art").show();//可以改成$(".childeMenu").show()	  	 	 	 else	  	 	 	 	 $("#art").hide();//可以改成$(".childeMenu").hide()	  	 	 })	  	 });	  </script>

2b27f004b5fb43a92ba47ffb83bab95bacb5ca144c5a7ea3975508795adba89e文学艺术5db79b134e9f6b82c0b36e0489ee08ed

有几个问题

<!DOCTYPE html><html><head>	<meta charset="utf-8">	<style type="text/javascript">	.childeMenu{display:none;list-style:none;}	</style>	<script type="text/javascript">		function show(id){			var ul=document.getElementById(id);// 这里需要修改			if(ul.style.display != "none"){ // 这里需要修改, 因为不设置时, 此属性是""而非"block"				ul.style.display = "none";			}else{				ul.style.display = "block";			}		}	</script></head><body>	<b><img src="2.jpg" width="100" height="100" />树形菜单:</b>	<br />	<!--下方需要传id进去: 'art'-->	<b><a href="javascript:show('art');"><img src="1.jpg"  width="100" height="100"  />文学艺术</a></b>	<ul  id="art" class="childeMenu">		<li><img src="1.jpg" width="100" height="100"  />先锋</li>		<li><img src="3.jpg" width="100" height="100" />感恩</li>	</ul></body></html>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn