Javacript代码ct100在本地工作但不能在现场工作 [英] Javacript code ct100 working in local but not work in live

查看:90
本文介绍了Javacript代码ct100在本地工作但不能在现场工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的代码中使用了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(&#39;ctl00_ContentPlaceHolder1_txt_geboy_g&#39; + 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 the ClientID 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 at ClientIDMode 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆