如何访问RUNAT ="服务器"使用JavaScript ASP元素?

编程入门 行业动态 更新时间:2024-10-24 02:01:04
本文介绍了如何访问RUNAT ="服务器"使用JavaScript ASP元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

似乎每个人都这样做(在code职位等)...但我不知道'如何:(

It seems everyone is doing this (in code posts etc.)...but I dont' know how :(

每当我尝试使用JavaScript来操纵一个asp的元素,我收到了元素为空或文件是不确定的等错误.....

whenever i try to manipulate an asp element using javascript i get a "element is null" or "document is undefined" etc. error.....

JavaScript的通常工作得很好,...但只有当我添加=服务器属性不元素似乎看不到我的JavaScript。

javascript works fine usually,...but only when i add the runat="server" attribute does the element seem invisible to my javascript.

任何建议,将AP preciated

any suggestions would be appreciated

谢谢,安德鲁

推荐答案

什么是可能发生的是,你的元素/控制是在其中充当命名容器(母版页的ITemplate,向导等),一个或多个ASP.NET控件,这也是造成其ID更改。

What's probably happening is that your element/control is within one or more ASP.NET controls which act as naming containers (Master page, ITemplate, Wizard, etc), and that's causing its ID to change.

您可以使用查看源文件在浏览器中,以确认这是什么发生在呈现的HTML。

You can use "view source" in your browser to confirm that's what's happening in the rendered HTML.

如果您的JavaScript是在ASPX页面,最简单的方法来暂时解决就是为的使用元素的ClientID属性。例如,如果你有,你想通过JS来参一控名为TextBox1的:

If your JavaScript is in the ASPX page, the easiest way to temporarily work around that is to use the element's ClientID property. For example, if you had a control named TextBox1 that you wanted to reference via JS:

var textbox = document.getElementById('<%= TextBox1.ClientID %>');

更多推荐

如何访问RUNAT =&QUOT;服务器&QUOT;使用JavaScript ASP元素?

本文发布于:2023-06-08 03:54:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/576166.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   服务器   QUOT   RUNAT   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!