<script type="text/javascript">
window.onload = function () {
var imgs = document.images;
for (var i = 0; i < imgs.length; i++)
{
(function (x) {
imgs[x].onclick = function () {
alert(x);
}
})(i);
}
};
</script>