1. Click event for a P element
1"http://www.w3.org/1999/xhtml">2"Server">3<title> Untitled Page </title>4<script type="Text/javascript">5 function ClickMe () {6Alert'Zhang Jing is a dung heap .');7 }8</script>9Ten<body> One<form id="Form1"runat="Server"> A<div> -<p onclick="ClickMe ();"> Click me </p> -</div> the</form> -</body> -2. Click events for all P elements
1"http://www.w3.org/1999/xhtml">23<title></title>4<meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/>5<script type="Text/javascript">6Window.onload = function () {//page all elements loaded complete7 varItems = document.getElementsByTagName ("P");//get all P elements in a page8 for(varI=0; i < items.length;i++) {//Loops9Items[i].onclick = function () {//Add an onclick event to each pTen //doing something ... OneAlert"suc!"); A } - } - } the</script> - -<body> -<p> Test 1</p> +<p> Test 2</p> -</body> +3, with a circular
1"http://www.w3.org/1999/xhtml">23<title></title>4<meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/>5<script type="Text/javascript">6Window.onload = function () {//page all elements loaded complete7 varItems = document.getElementsByTagName ("P");//get all P elements in a page8 for(varI=0; i < items.length;i++) {//Loops9Items[i].onclick = function () {//Add an onclick event to each pTen //doing something ... OneAlert"suc!"); A } - } - } the</script> - -<body> -<p> Test 1</p> +<p> Test 2</p> -</body> +Sharp jquery (the onclick () event of P)