Javacript代码ct100在本地工作但不能在现场工作 [英] Javacript code ct100 working in local but not work in live
问题描述
我在我的代码中使用了ctl00_ContentPlaceHolder1。它在当地工作。但不能在现场工作
我尝试过的事情:
< pre lang =C#>我创建的代码类似于这个
< pre lang = C#> var geboy_g = document.getElementById(&#39; ctl00_ContentPlaceHolder1_txt_geboy_g&#39; + k)。 value ; < / pre >
在本地工作但 我在运行 实时错误,如 this
ncaught TypeError:无法读取' value' -keyword> null
感谢 advance
在客户端处理服务器控件时,使用控件的ClientID
。例如:
JavaScript:
var x = document .getElementById(' <% = YourControl.ClientID%>')。value;
jQuery:
var x =
(' #<%= YourControl.ClientID%>')。val();
此外,如果您使用的是4.0版本,则可以查看控件的ClientIDMode
属性以生成清洁程序id: ScottGu的博客 - 使用ASP.NET 4 Web窗体清理HTML标记 - 客户端ID(VS 2010和.NET 4.0系列) [ ^ ]
i have use ctl00_ContentPlaceHolder1 in my code. it working local. but not working in live
What I have tried:
i have create code like this
<pre lang="C#">var geboy_g = document.getElementById('ctl00_ContentPlaceHolder1_txt_geboy_g' + k).value;</pre>
it is working in local. but when i have run in live error like this
ncaught TypeError: Cannot read property 'value' of null
thanks in advance
Use theClientID
of the control when dealing with server controls at the client. For example:
JavaScript:
var x = document.getElementById('<%= YourControl.ClientID %>').value;
jQuery:
var x =
('#<%= YourControl.ClientID %>').val();
Also, if you were using 4.0 version, you can take a look atClientIDMode
property of the control to generate cleaner id's: ScottGu's Blog - Cleaner HTML Markup with ASP.NET 4 Web Forms - Client IDs (VS 2010 and .NET 4.0 Series)[^]
这篇关于Javacript代码ct100在本地工作但不能在现场工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!