怎样用js获取一段HTML代码里的图片地址
<table border= "1 " width= "100% " id= "table1 ">
<tr>
<td width= "1024 "> xcvxb </td>
<td> uio[uio[uio[uio[ </td>
<td> uio[uio[ </td>
</tr>
<tr>
<td width= "1024 "> xcvncxvn </td>
<td>
ui0o[puio;uio[iuo[ </td>
<td> uio[uio[ </td>
</tr>
<tr>
<td width= "1024 "> xcvncxvnxcvmvxcmv <img border= "0 " src= "= "../uploadfile/images/index.gif " width= "222 " height= "132 "> </td>
<td> uio[uio[iuo[uio[ui[ouio[ui </td>
<td> uio[uio[iuo[uio[ui </td>
</tr>
<tr>
<td width= "1024 "> nvcxb;lkjgm 'psdljrflks;lfkgmsd ';lc?>XVnx </td>
<td>
<img border= "0 " src= "../uploadfile/images/index.gif " width= "1024 " height= "732 "> </td>
<td> uio[uio[uio[iuo[ui </td>
</tr>
</table>
上面代码图片显示的数量不定,现在我想通过js编写一段代码,不管有多少张图片,让它自动将所有图片的URL获取出来,也就是 <img border= "0 " src= "../uploadfile/images/index.gif " width= "1024 " height= "732 "> 中src= " "两个引号间的图片地址取出来,请高手帮忙写这段代码
------解决方案-------------------- <img border= "0 " src= "../uploadfile/images/index.gif " width= "1024 " height= "732 " id= 'image_a '>
<script>
var image_a=document.getElementById( 'image_a ');
var image_src=image_a.src;/////这个是地址
</script>
------解决方案--------------------image的id使用id= "tr_img <%# Container.ItemIndex + 1%> "让他自动递增
然后在js里面用循环根据其id反问这些图片的src属性
------解决方案-------------------- <!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= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
<SCRIPT LANGUAGE= "JavaScript ">
<!--
var arr = new Array();
var iCounts = 0;
function CheckAll()
{
for (var i=0;i <document.images.length;i++)
{
arr[iCounts] = document.images[i].src;
iCounts++
}
for(var ix=0; ix <arr.length; ix++)
{
alert(arr[ix]);
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<img SRC= "1.jpg ">
<img SRC= "2.jpg ">
<img SRC= "3.jpg ">
<INPUT TYPE= "button " onclick= "CheckAll(); " value= "TEST> > > > ">
</BODY>
</HTML>
------解决方案--------------------同意楼上的
用document.getElementsByTagName( 'img ')应该也能获取所有的图片
如果你是要获取页面上某一部份的图片可以给那一部分加个div 设id为 'xxx '则代码应为