日期:2014-05-17 浏览次数:20514 次
$("a").hover(function() { alert($("a").index(this)); });
------解决方案--------------------
jQuery获取当前元素的索引值
$("a").hover(function(){
alert($("a").index(this));
});
------解决方案--------------------
$("div a").bind("click", function() {
alert($("div a").index(this));
});
------解决方案--------------------
上面 都说了
------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT="Sandy(阿非)"> <META NAME="Keywords" CONTENT="Sandy,阿非"> <META NAME="Description" CONTENT=""> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script> $(function(){ $('a').each(function(i){ this.onclick=function(){ alert(i); return false; }; }); }); </script> </HEAD> <BODY> <a href="">百度</a> <a href="">google</a> <a href="">msn</a> <a href="">qq</a> <a href="">sina</a> </BODY> </HTML>
------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT="Sandy(阿非)"> <META NAME="Keywords" CONTENT="Sandy,阿非"> <META NAME="Description" CONTENT=""> <script> window.onload=function(){ var a=document.getElementsByTagName("a"); if(!a) return; for(var i=0,len=a.length;i<len;i++) { (function(){ var temp=i; a[i].onclick=function(){ alert(temp); return false; }; })(); } } </script>