jquery 绑定相同id元素事件的方法

用$('[id=idName]')这种格式,就可以绑定到相同id的元素

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script type="text/javascript"> 
	$().ready(function(){
		$('[id=testA]').click(function(){
			alert($(this).attr("name"));
		});
	});
  </script>
 </head>

 <body>
  <a href="javascript:void(0)" id = "testA" name="1">黑色头发</a>
  <a href="javascript:void(0)" id = "testA" name="2">紫色头发</a>
  <a href="javascript:void(0)" id = "testA" name="3">工程师</a>
  <a href="javascript:void(0)" id = "testA" name="4">java</a>
 </body>
</html>


黑色头发:http://heisetoufa.iteye.com/

你可能感兴趣的:(JavaScript,java,jquery,绑定,相同id)