-5
<img src="pic1.jpg" class="mythumbs">
<img src="pic2.jpg" class="mythumbs">
<img src="pic3.jpg" class="mythumbs">
<img src="pic4.jpg" class="mythumbs">

<script>
/*
here is the code which makes me when i click on any image, it shows me its src attribute
(without using idTag 'preferred'). 
*/

alert(theAttribute);
</script>

我需要输入一个代码来显示单击项目的 src 属性而不使用 idTags

4

2 回答 2

4
$(function(){
  $("img.mythumbs").click(function(){
    alert($(this).attr("src"));    
  });
});

此代码将提醒所有img具有 css 类的元素的 src 属性mythumbs

工作样本:http: //jsfiddle.net/tZcpw/1/

于 2012-04-27T14:23:39.860 回答
1

这是一个没有IDand的解决方案Classsrc当您单击图像时,这将发出警报。

$("img").click(function(){
    alert($(this).attr("src"));    
});

$("img")如果你想用$(".your_class-here")一个类来做这个,你可以替换为。

是一个有效的现场演示。

于 2012-08-27T13:53:58.393 回答