2012-02-05 90 views
0

我有图片的路径,如下图所示:图片src使用jQuery

<img src='Uploads/" + document.getElementById("<%=currentDirectory.ClientId%>").value + "/" + file.name + "' width='70' height='55'/> 

,现在我想,以显示其原单图像点击这个缩略图。 对于我做这样的:

$(".imgContain").click(function() { 
       $('#<%=largeImage.ClientId%>').attr('src','Uploads/" + document.getElementById("<%=currentDirectory.ClientId%>").value + "/" + file.name + "'); 

    }); 

当我做到这一点的方式,并检查其SRC它显示我为“无法加载给URL”。 任何人都可以编辑我这个src或指出我哪个是最好的方法来做到这一点?

这是我的HTML部分:

<div id="thumbs" class="imgContain" runat="server"> 
    </div> 

<asp:Image ID="largeImage" runat="server" 
     style="position:relative;width:450px;height:345px; margin-left:430px;margin-top:-415px; margin-bottom:30px;" 
     BorderColor="#666666" BorderStyle="Dashed" BorderWidth="4px"/> 
+0

是你的任何机会在外部文件的JavaScript? – 2012-02-05 00:09:52

+0

@ Mikey-No它在主脚本内 – coder 2012-02-05 00:10:59

+0

您可以向我们展示实际生成的HTML而不是您的ASP代码。我们不知道实际上在页面中放置了什么,因此我们不知道实际运行的代码(您可能不知道)。在浏览器中获取实际生成的代码的地方是View/Source。 – jfriend00 2012-02-05 00:14:55

回答

1

是啊,这串有点过。试试这样:

$('.imgContain').click(function() { 
    $('#<%=largeImage.ClientId%>').attr('src','Uploads/' + $get('<%=currentDirectory.ClientId%>').value + '/' + file.name); 
}); 

这是有点令人困惑,因为单引号和双引号互换使用。

+0

@ Will-非常感谢您的编辑,因为我真的在过去的一天里拔掉了我的头发。 – coder 2012-02-05 09:16:07

0

我不是100%肯定,但我想你可能需要获得服务器标记出的字符串。

也许是这样的:

$(".imgContain").click(function() { 
       $('#' + <%=largeImage.ClientId%>).attr('src','Uploads"' + document.getElementById(<%=currentDirectory.ClientId%>).value + "/" + file.name + "'"); 

    });