本文介绍了如何在javascript中设置锚标记的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 hi i我在网站上进行缩放功能 hii am doing the website with functionality of zooming<span> <a id="placeholder" runat="server" rel="zoom-width:600px; zoom-height:600px" class="MagicZoom"> <asp:Image ID="images" BorderWidth="1px" BorderColor="LightGray" runat="server" onerror="this.onerror=null;this.src='../Image/noimage2.png'" Width="250px" /></a> </span> 页面加载 i我分配的价值如 this.images.ImageUrl =../Image/temp/+ stylecode.Trim()+。jpeg; 占位符.HRef =../Image/temp/+ style_code.Trim()+。jpeg; 鼠标悬停我使用的功能如 string mainimgurl =../ Image / temp /+ st yle_code.Trim()+ hdncolorcode.Value.Trim()+。jpeg; lblcolorname.Attributes.Add(onmouseover,javascript:setmainimgg('+ mainimgurl +') ;); 和javascript函数是 on page loads i am assigning the value likethis.images.ImageUrl = "../Image/temp/" + stylecode.Trim() + ".jpeg"; placeholder.HRef = "../Image/temp/" + style_code.Trim() +".jpeg";on mouse over i am using the function likestring mainimgurl = "../Image/temp/" + style_code.Trim() + hdncolorcode.Value.Trim() + ".jpeg"; lblcolorname.Attributes.Add("onmouseover", "javascript:setmainimgg('" + mainimgurl + "');");and javascript function isfunction setmainimgg(iiisd) { document.getElementById(<%= images.ClientID %>).src = iiisd; document.getElementById(<%= placeholder.ClientID %>).href = iiisd; }here images control value is changed it's shows the correct image. But the problem is href(anchor tag) path is not changing. if the value path changes means the zoom will work i can't assign the value for anchor tag. 推荐答案 <a id="placeholder" runat="server" rel="zoom-width:600px; zoom-height:600px" class="MagicZoom"> 看起来在你的JS代码中没有正确声明占位符元素: looks like the "placeholder" element is not declared properly in your JS code:// This line seems to have a fault:placeholder.HRef = "../Image/temp/" + style_code.Trim() +".jpeg";// Use this instead:document.getElementById("placeholder").href = "../Image/temp/" + style_code.Trim() +".jpeg"; 干杯, Edo 这篇关于如何在javascript中设置锚标记的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 05:39