JavaScript图像对象
有人能告诉我如何使用JavaScript访问下面的HTML行吗?我似乎无法在JavaScript中找到图像对象:JavaScript图像对象,javascript,html,Javascript,Html,有人能告诉我如何使用JavaScript访问下面的HTML行吗?我似乎无法在JavaScript中找到图像对象: <td colspan="2" rowspan="5"><img src="../image/6765.jpg" width="330" height="130" /> 最终的结果是我想更改图像。谢谢你的帮助 你应该给你的元素一个唯一的id: 或者。。。搜寻其出现次数(0,1,2或更多x) 例如,在此页上查找“.jpg”或“.png”或“.gif” ja
<td colspan="2" rowspan="5"><img src="../image/6765.jpg" width="330" height="130" />
最终的结果是我想更改图像。谢谢你的帮助 你应该给你的
元素一个唯一的id
:
或者。。。搜寻其出现次数(0,1,2或更多x) 例如,在此页上查找“.jpg”或“.png”或“.gif”
javascript:
for(i in document.images)
if(/\/image\/6765\.jpg/.test(document.images[i].src))
/* resolve the base address with the '..' for a more stringent test */
alert([ 'image URI found at image index: ', i,
'\n\nimage.src is\n', document.images[i].src ])
发现:
在图像索引处找到图像URI:,0
image.src是,http://static.adzerk.net/Advertisers/c9180f024ecb4880954922ef7a72be87.gif
在图像索引处找到图像URI:,4 image.src是
,http://static.adzerk.net/Advertisers/2568.jpg
在图像索引处找到图像URI:,6 image.src是
,http://sstatic.net/ads/img/careers2-ad-header-so.png
document.getElementById('myImage').src = 'new-image.jpg';
javascript:
for(i in document.images)
if(/\/image\/6765\.jpg/.test(document.images[i].src))
/* resolve the base address with the '..' for a more stringent test */
alert([ 'image URI found at image index: ', i,
'\n\nimage.src is\n', document.images[i].src ])
javascript:
for(i in document.images)
if(/\.(jpg|gif|png)/.test(document.images[i].src))
alert([ 'image URI found at image index: ', i,
'\n\nimage.src is\n', document.images[i].src ])