使用JavaScript出现问题 [英] Problem using javascript
本文介绍了使用JavaScript出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好!
我正在尝试使用Java脚本设置图像源和href锚标记,但是它不起作用.
Hello!!
i am trying to set the source for an image and href for an anchor tag using java script but it isn''t working.
<script type="text/JavaScript" >
function Zoom() {
var BigImage = document.getElementById("HiddenFeild1").value;
var SmallImage = document.getElementById("HiddenFeild2").value;
document.getElementById("zoom1").href = BigImage;
document.getElementById("Img1").src = SmallImage;
}
</script>
<asp:HiddenField id="HiddenFeild1" runat="server" value=""/>
<asp:HiddenField id="HiddenField2" runat="server" value=""/>
<a id="zoom1" class="cloud-zoom" rel="position:''inside''">
<img alt="" id="Img1" runat="server" /></a>
这是背后的代码
here is the code behind
private void databind()
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from ImageZoom", con);
DataSet ds = new DataSet();
da.Fill(ds);
dtlist1.DataSource = ds;
dtlist1.DataBind();
HiddenFeild1.Value = "Images/" + ds.Tables[0].Rows[0][3].ToString();
HiddenField2.Value = "Images/" + ds.Tables[0].Rows[0][2].ToString();
con.Close();
}
推荐答案
设置锚标记href可以按照您描述的方式工作.图像标签(img)已被标记为runat="server"
,这实际上意味着id
属性现在是服务器端ID,与getElementById
中使用的客户端ID不同.
请参阅以下我的较早解决方案之一:启用带有以下内容的文本框javascript选中的复选框 [
Setting the anchor tags href should work the way you described it. The image tag (img) has been tagged asrunat="server"
this effectively means that theid
attribute is now the server side id which is not the same as the client side id used ingetElementById
.
See here in one of my earlier solutions: enable textbox with checkbox checked with javascript[^].
Hope you can work it out.
Regards,
Manfred
这篇关于使用JavaScript出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文