如何在javascript中设置锚标记的值 [英] how to set the value for the anchor tag in javascript

查看:50
本文介绍了如何在javascript中设置锚标记的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


i我在网站上进行缩放功能



hi
i 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 like

this.images.ImageUrl = "../Image/temp/" + stylecode.Trim() + ".jpeg";

placeholder.HRef = "../Image/temp/" + style_code.Trim() +".jpeg";

on mouse over i am using the function like
string mainimgurl = "../Image/temp/" + style_code.Trim() + hdncolorcode.Value.Trim() + ".jpeg";
lblcolorname.Attributes.Add("onmouseover", "javascript:setmainimgg('" + mainimgurl + "');");

and javascript function is

function 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.

推荐答案

您正在尝试编辑占位符元素。

但是,看起来像占位符元素在JS代码中未正确声明,请尝试使用< b> document.getElementById :

You are trying to edit the placeholder element.
However, looks like the "placeholder" element is not declared properly in your JS code, try to use document.getElementById:
<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


访问这里....



http://stackoverflow.com/questions/9148432/how-to-add -a-certain-value-to-anchor-tag [ ^ ]
Visit Here....

http://stackoverflow.com/questions/9148432/how-to-add-a-certain-value-to-anchor-tag[^]


这篇关于如何在javascript中设置锚标记的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆