Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript图像对象_Javascript_Html - Fatal编程技术网

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

有人能告诉我如何使用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”

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 ])