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.

Javascript 事件處理 - 基本教學 By 彭彭 20

Posted at
7. 
	a. 選單開合操作範例

WS000016.JPG

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"></meta>
	<title>Event 事件處理</title>
	<script type="text/javascript">
	//alert("hello");
	function over(element){
		element.style.color="pink";
	}
	function out(element){
		element.style.color="blue";
	}
	// 用JavaScript 動態的注冊事件處理器 */
	function init(){
		var btn = document.getElementById("btn");
		/*
		btn.onclick = function(){
			alert("clicked");
		}*/
		var handler =function(){
			alert("clicked");
		}
		btn.addEventListener("click"/* 事件的名稱 */,handler);
	}
	</script>
</head>
<body onload="init();">
	<button id = "btn">Click</button>
	<!-- 靜態的處理 -->
	<span onmouseover="over(this);" onmouseout="out(this);">florence</span>
</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?