2012-05-01 25 views
0

我收到以下錯誤代碼。 我正在使用中繼器顯示圖像。圖像ID是IMG。在jquery我使用$("#<%=img.ClientID %>")獲取圖像。但是它給出的錯誤如img在當前上下文中不存在。中繼器ID是rptRepeater。 我該如何解決這個問題? $("#<%=img.ClientID %>") doesnot exists in current context圖像ID在當前上下文中不存在asp.net

.NET代碼

<asp:Repeater ID="RepeaterView" runat="server"> 
    <ItemTemplate> 
     <a onmouseout="SelectEnd()" onmouseover='<%#Eval("Coords","preview(\"{0}\");")%>'>  
      <asp:Image ID="ImageZoom" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %> ' Height="150" Width="150" >  
      </asp:Image> 
     </a> 
    </ItemTemplate> 
</asp:Repeater> 

JavaScript代碼

<script type="text/javascript"> 
    function preview(Coords) { 
     var arrResult = Coords.split(","); 
     var nx1 = arrResult[0]; 
     var ny1 = arrResult[1]; 
     var nx2 = arrResult[2]; 
     var ny2 = arrResult[3]; 
     var ias = $("#<%=ImageZoom.ClientID %>").imgAreaSelect({ instance: true }); 
     ias.setSelection(nx1, ny1, nx2, ny2, true); ias.setOptions({ show: true });  
     ias.update(); 
    } 
</script> 
+0

我認爲你缺少一半的職位。 – epascarello

+0
+0

你爲什麼要添加它作爲一個評論,而不是在代碼? – epascarello

回答

0

你有問題是有是沒有一個ID,您要添加多個元素的頁面,因此該代碼無法處理所有元素。你需要使它更通用。

嘗試並更改您的代碼,使其不需要ID。

.NET代碼

<asp:Repeater ID="RepeaterView" runat="server"> 
    <ItemTemplate> 
     <a onmouseout="SelectEnd()" onmouseover='<%#Eval("Coords","preview(this, \"{0}\");")%>'>  
      <asp:Image ID="ImageZoom" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %> ' Height="150" Width="150" >  
      </asp:Image> 
     </a> 
    </ItemTemplate> 
</asp:Repeater> 

JavaScript代碼

<script type="text/javascript"> 
    function preview(elem, Coords) { 
     var arrResult = Coords.split(","); 
     var nx1 = arrResult[0]; 
     var ny1 = arrResult[1]; 
     var nx2 = arrResult[2]; 
     var ny2 = arrResult[3]; 
     var ias = $(elem).find("img").imgAreaSelect({ instance: true }); 
     ias.setSelection(nx1, ny1, nx2, ny2, true); ias.setOptions({ show: true });  
     ias.update(); 
    } 
</script> 
相關問題