0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HTML DOM - 選單開合範例 By 彭彭

Last updated at Posted at 2018-08-18
6. HTML DOM
	b. 選單開合操作範例

WS000015.JPG

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"></meta>
	<title>HTML DOM 選單開合操作</title>
	<script type="text/javascript">
	//alert("hello");
	function toggleMenu(number){
		var menu = document.getElementById("menu-" + number);
		menu.classList.toggle("hide");//切換標簽物件class的 hide的設定
	/*	if(menu.style.display == "none"){// 目前是none
			menu.style.display = "block";
		}else{
		menu.style.display = "none";// 目前是block
		}*/
	}
	</script>
	<style type = "text/css">
	.hide{display:none;}
	</style>
</head>
	<body>
	<div onclick = "toggleMenu(1);">florence1</div>
	<ul id = "menu-1">
		<li>1-0825</li>
		<li>1-0826</li>
		<li>1-0827</li>
	</ul>
	
	<div onclick = "toggleMenu(2);">florence2</div>
	<ul id = "menu-2">
		<li>2-0825</li>
		<li>2-0826</li>
		<li>2-0827</li>
	</ul>
	
	<div onclick = "toggleMenu(3);">florence3</div>
	<ul id = "menu-3">
		<li>3-0825</li>
		<li>3-0826</li>
	</ul>
	</body>
</html>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?