似乎每个人都这样做(在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元素?
发布评论