求助:点击网页图片后如何获得图片的路径?

xxy5311 2008-06-04 05:55:05
点击网页图片后如何获得图片的路径?

document.write("<img src='" + filePath + "' width=144px height=115px />");
打印出若干图片~
我点击图片的时候怎么获得src的内容呢?
谢谢~~
...全文
139 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
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);
}




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

JScript code
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的烂浏览器~~~
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 chinmo 的回复:]
JScript code
function showimg(value){
alert(value);
}


document.write(" <img src='" + filePath + "' width=144px height=115px onclick="showimg(this.src)" />");
[/Quote]
xxy5311 2008-06-05
  • 打赏
  • 举报
回复
还是不行~~
zhao860216 2008-06-05
  • 打赏
  • 举报
回复

function show(value){
alert(value);
}


for(var i=0 ; i <4 ; i++){
document.write(" <img src='" + filePath + "' width=144px height=115px />"+"onclick=show(this.src)");
}

试试看:
(:D
浴火_凤凰 2008-06-05
  • 打赏
  • 举报
回复
for(var i=0 ; i <4 ; i++){
document.write(" <img src='" + filePath + "' width=144px height=115px />"+"onclick='alert("+this.src+")'");
}
Go 旅城通票 2008-06-05
  • 打赏
  • 举报
回复
document.onclick=function(e)
{
e=e||event;
var tag=e.target||e.srcElement;
if(tag.tagName=="IMG")alert(tag.src);
}
YH_Random 2008-06-05
  • 打赏
  • 举报
回复
document.write(" <img onclick='alert(this.src)' src='" + filePath + "' width=144px height=115px />");
xxy5311 2008-06-05
  • 打赏
  • 举报
回复
PS:
我的意思是我的页面上有很多张图片!!
我点击某张图片的时候就获得这张图片的src=""~~
xxy5311 2008-06-04
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 jhwcd 的回复:]
引用 3 楼 xxy5311 的回复:
引用 1 楼 familyX 的回复:
HTML code
document.write(" <img id="pic" src='" + filePath + "' width=144px height=115px />");

alert(document.getElementById("pic").src)


这不行~~
因为我有个循环打印了若干个~~

for(var i=0 ; i <4 ; i++){
document.write(" <img src='" + filePath + "' width=144px height=115px />");
}

如果这样的话每次得到的只是第一张的~~ …
[/Quote]
如果我有100个~
那我不就要写100个getElementById?
jhwcd 2008-06-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xxy5311 的回复:]
引用 1 楼 familyX 的回复:
HTML code
document.write(" <img id="pic" src='" + filePath + "' width=144px height=115px />");

alert(document.getElementById("pic").src)


这不行~~
因为我有个循环打印了若干个~~
for(var i=0 ; i <4 ; i++){
document.write(" <img src='" + filePath + "' width=144px height=115px />");
}

如果这样的话每次得到的只是第一张的~~
我要得到我选中的那一章的s…
[/Quote]
你读的时候加个for循环不就能读出来了吗离别id="pic0",id="pic1"等等。
  • 打赏
  • 举报
回复

function showimg(value){
alert(value);
}


document.write(" <img src='" + filePath + "' width=144px height=115px onclick="showimg(this.src)" />");
xxy5311 2008-06-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xiaoqiangcn 的回复:]
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>


<%=path%>就可以显示路径
[/Quote]
只能用纯javascript~~
谢谢您的回答~
xxy5311 2008-06-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 familyX 的回复:]
HTML code
document.write(" <img id="pic" src='" + filePath + "' width=144px height=115px />");

alert(document.getElementById("pic").src)
[/Quote]

这不行~~
因为我有个循环打印了若干个~~
for(var i=0 ; i<4 ; i++){
document.write(" <img src='" + filePath + "' width=144px height=115px />");
}

如果这样的话每次得到的只是第一张的~~
我要得到我选中的那一章的src~~
xiaoqiangcn 2008-06-04
  • 打赏
  • 举报
回复
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>


<%=path%>就可以显示路径
familyX 2008-06-04
  • 打赏
  • 举报
回复

document.write(" <img id="pic" src='" + filePath + "' width=144px height=115px />");

alert(document.getElementById("pic").src)

87,907

社区成员

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

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