如何从 Javascript 访问 asp:Image?
我的服务器标记中有一个 asp:Image,如下所示:
<asp:Image ID="Img1" runat="server"/>
现在,我想在我的 javascript 中找到这个 img,但似乎遇到了 ASP.Net 混淆我的名字的问题。 客户端标记看起来像这样:
<img id="ctl00_Content_Img1"/>
我想这是因为所有内容都在名为“Content”的表单元素内,我猜这很正常? :)
有关如何从 javascript 访问它的任何指示吗?
[编辑]我在想是否有一种简单的方法来更改我的javascript“servertime”以搜索混淆的ID?
I got an asp:Image in my server-markup like this:
<asp:Image ID="Img1" runat="server"/>
Now, I want to find this img in my javascript, but seem to run into the problem of ASP.Net obfuscating my names. The client-markup will look something like this:
<img id="ctl00_Content_Img1"/>
I imagine this is because everything is inside a form-element called 'Content', which is quite normal I guess? :)
Any pointers on how to access this from javascript?
[EDIT] I was thinking if there's an easy way to change my javascript "servertime" to search for the obfuscated id ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在这里,您可以通过使用服务器控件的 ClientID 属性来获取服务器控件的客户端 ID,如下所示:
Here you can get a server control's client side id by using it's ClientID property like that :
您可以使用 ClientID 属性获取服务器端生成的 Id 的客户端引用:
You can obtain a client reference of the Id generated on the server-side with the ClientID property:
只是将之前的两个答案放在一起:
Just to put the two previous answers together:
您想要使用
document.getElementById
函数。You want to use the
document.getElementById
function.