如何获取具有相同类的图像的 src 值并将它们写入/输出到空 div 中?
例如:
<body>
<img class="class1" src="http://www.mysite.com/img/image1.jpg" width="168" height="168" alt="">
<img class="class1" src="http://www.mysite.com/img/image2.jpg" width="168" height="168" alt="">
<img class="class1" src="http://www.mysite.com/img/image3.jpg" width="168" height="168" alt="">
<img class="class1" src="http://www.mysite.com/img/image4.jpg" width="168" height="168" alt="">
<img class="class1" src="http://www.mysite.com/img/image5.jpg" width="168" height="168" alt="">
<img class="class2" src="http://www.mysite.com/img/image6.jpg" width="168" height="168" alt="">
<img class="class2" src="http://www.mysite.com/img/image7.jpg" width="168" height="168" alt="">
<img class="class2" src="http://www.mysite.com/img/image8.jpg" width="168" height="168" alt="">
<img class="class2" src="http://www.mysite.com/img/image9.jpg" width="168" height="168" alt="">
<img class="class2" src="http://www.mysite.com/img/image10.jpg" width="168" height="168" alt="">
<div id="print-src">
<!-- Print Result Here -->
</div>
</body>
结果(如果我只想检索具有 class1 类的图像的 src 值):
<body>
...........................
<div id="print-src">
http://www.mysite.com/img/image1.jpg
http://www.mysite.com/img/image2.jpg
http://www.mysite.com/img/image3.jpg
http://www.mysite.com/img/image4.jpg
http://www.mysite.com/img/image5.jpg
</div>
</body>