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

WBOY
Release: 2016-06-24 11:57:35
Original
809 people have browsed it


.childeMenu{display:none;list-style:none;}


function show(id){
var ul=document.getElementById("id");
if(ul.style.display=="block"){
ul.style.display="none";
}else{
ul.style.display="block";
}
}



树形菜单:

文学艺术

  

  • 先锋

  •     
  • 感恩


  • 回复讨论(解决方案)

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

    你没有id="id"的元素

    赞同楼上

    赞同楼上

    你没有给show传id参数

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


     <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>
    Copy after login

    文学艺术

    有几个问题

    <!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>
    Copy after login

    Related labels:
    source:php.cn
    Statement of this Website
    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
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template