Home  >  Article  >  Web Front-end  >  设置图片的显示与影藏,我的代码点击的时候不起作用,怎么回事呢?_html/css_WEB-ITnose

设置图片的显示与影藏,我的代码点击的时候不起作用,怎么回事呢?_html/css_WEB-ITnose

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


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


设置图片的显示与影藏,我的代码点击的时候不起作用,怎么回事呢?_html/css_WEB-ITnose树形菜单:


设置图片的显示与影藏,我的代码点击的时候不起作用,怎么回事呢?_html/css_WEB-ITnose文学艺术

      
  • 设置图片的显示与影藏,我的代码点击的时候不起作用,怎么回事呢?_html/css_WEB-ITnose先锋

  •     
  • 设置图片的显示与影藏,我的代码点击的时候不起作用,怎么回事呢?_html/css_WEB-ITnose感恩


回复讨论(解决方案)

改成
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>

设置图片的显示与影藏,我的代码点击的时候不起作用,怎么回事呢?_html/css_WEB-ITnose文学艺术

有几个问题

<!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"    style="max-width:90%"  style="max-width:90%" / alt="设置图片的显示与影藏,我的代码点击的时候不起作用,怎么回事呢?_html/css_WEB-ITnose" >树形菜单:</b>	<br />	<!--下方需要传id进去: 'art'-->	<b><a href="javascript:show('art');"><img  src="1.jpg"     style="max-width:90%"  style="max-width:90%"  / alt="设置图片的显示与影藏,我的代码点击的时候不起作用,怎么回事呢?_html/css_WEB-ITnose" >文学艺术</a></b>	<ul  id="art" class="childeMenu">		<li><img  src="1.jpg"    style="max-width:90%"  style="max-width:90%"  / alt="设置图片的显示与影藏,我的代码点击的时候不起作用,怎么回事呢?_html/css_WEB-ITnose" >先锋</li>		<li><img  src="3.jpg"    style="max-width:90%"  style="max-width:90%" / alt="设置图片的显示与影藏,我的代码点击的时候不起作用,怎么回事呢?_html/css_WEB-ITnose" >感恩</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