用jquery获取元素的id名称

发布时间:2017年2月28日 作者:未知 查看次数:1283

用jquery获取元素的id名称

代码:


<!DOCTYPE html> 

<html>

<head> 

<meta http-equiv="Content-Type"  content="text/html;  charset=utf-8" />

<script type="text/javascript" src="jquery.js"></script>

</head>

<body>

<img id="mPicID1" src="photo/lw.png">

<img id="mPicID2" src="photo/lw.png">


<script>

$(document).ready(function() {

$('#mPicID1').each(function(){

                $(this).click(

                    function(){alert($(this).attr('id'));

                        });

            });

$("#mPicID2").bind("click",

function() {

alert($(this).attr('id'));

}

);

});


</script>

</body>

</html>




版权所有!www.sieye.cn
E.Mail:sieye@sohu.com QQ:66697110