当前位置: 代码迷 >> Web前端 >> jquery中运用each方法获取当前对象
  详细解决方案

jquery中运用each方法获取当前对象

热度:49   发布时间:2012-08-26 16:48:06.0
jquery中使用each方法获取当前对象
引用
js文件:

<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
	<script type="text/javascript">
	$(document).ready(function(){
		$("ul li").each(function(index){
		  $(this).click(function(){
		  	var currentText = $(this).text();
		  	if(currentText == "单击1"){
		  		alert("单击1")
		  	}
		  	if(currentText == "单击2"){
		  		alert("单击2")
		  	}
		  })	
		
		})
	})
</script>

引用
html文件:

<body>
	 <ul>
		 <li>单击1</li>
		 <li>单击2</li>
	</ul>
 </body>
  相关解决方案