点击网页图片后如何获得图片的路径

xxy5311 2008-06-05 05:10:46

for(var i=0 ; i<fileNames.length ; i++) {
fileName = fileNames[i];
document.write(" <td> ");
document.write(" <a href=""> ");
document.write("<img src='" + fileName + "' width=144px height=115px/>");
document.write("</a>");
}



我点击图片的时候怎么获得src的内容呢?
谢谢~~
...全文
125 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jackyBody 2008-06-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 YH_Random 的回复:]
for(var i=0 ; i <fileNames.length ; i++) {
fileName = fileNames[i];
document.write(" <td> ");
document.write(" <a href=""> ");
document.write(" <img onclick='getImageSrc(this)' src='" + fileName + "' width=144px height=115px/>");
document.write(" </a>");
}


function getImageSrc(img)
{
var test=img.src;
alert(test);
}
[/Quote]
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 tantaiyizu 的回复:]
onclick = "alert(this.src)"
[/Quote]
这个就可以啊~~~简单的问题,不要复杂化~~
Go 旅城通票 2008-06-06
  • 打赏
  • 举报
回复
机顶盒的浏览器????....................................
同情ing,没搞过这中浏览器
xxy5311 2008-06-06
  • 打赏
  • 举报
回复
TMD什么机顶盒的破浏览器?
我写成这样,取不出来~~

for(var i=0 ; i <fileNames.length ; i++) {
fileName = fileNames[i];
document.write("<img src='" + filePath + "' width=144px height=115px onclick='getImageSrc(this)'");
}

function getImageSrc(img)
{
var test=img.src;
alert(test);
}


我写成这样,还是取不出来~~

for(var i=0 ; i <fileNames.length ; i++) {
fileName = fileNames[i];
document.write("<img src='" + filePath + "' width=144px height=115px onclick='getImageSrc(this.src)'");
}

function getImageSrc(src)
{
// var test=img.src;
alert(src);
}

靠~~
在IE都可以~~
真TMD的烂浏览器~~~
YH_Random 2008-06-05
  • 打赏
  • 举报
回复
for(var i=0 ; i <fileNames.length ; i++) {
fileName = fileNames[i];
document.write(" <td> ");
document.write(" <a href=""> ");
document.write(" <img onclick='getImageSrc(this)' src='" + fileName + "' width=144px height=115px/>");
document.write(" </a>");
}


function getImageSrc(img)
{
var test=img.src;
alert(test);
}


YH_Random 2008-06-05
  • 打赏
  • 举报
回复
for(var i=0 ; i<fileNames.length ; i++) {
fileName = fileNames[i];
document.write(" <td> ");
document.write(" <a href=""> ");
document.write("<img onclick='alert(this.src)' src='" + fileName + "' width=144px height=115px/>");
document.write("</a>");
}

xxy5311 2008-06-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 tantaiyizu 的回复:]
onclick = "alert(this.src)"
[/Quote]
怎么把它传出来?
jacklinchen 2008-06-05
  • 打赏
  • 举报
回复
document.write("<img src='" + fileName + "' id='img1' name='img1' width=144px height=115px onclick = 'alert(img1.src)'/>");
tantaiyizu 2008-06-05
  • 打赏
  • 举报
回复
onclick = "alert(this.src)"

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧