第二次使用getElementById获取null [英] getting null with getElementById on second time

查看:92
本文介绍了第二次使用getElementById获取null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用JavaScript编写了一个函数,并在dropdown onchange事件上调用了该函数.像这样

I have written one fuction in javascript and calling that function on dropdown onchange event. like this

protected void Page_Load(object sender, EventArgs e)
{

 ddlanswer.Attributes.Add("onchange", "return OnSelectedIndexChange(this);");

}


我的javascript函数如下,


my javascript function is as below,

function OnSelectedIndexChange(ss)
{
 var txt1 = document.getElementById("<%=TxtAnswer11.ClientID%>");

if(ss.value == 3)
 {
 txt1.style.display = 'block';

}


我第一次得到这个txt1,但是第二次我得到那个txt1为null ...请给我这个问题的解决方案..


I am getting this txt1 on first time but second time i am getting that txt1 as null...Pls give me solution for this why this is happening..

推荐答案

您可以在Chrome中调试这些内容.您可以查看传入的内容以及脚本的外观.我不知道为什么样式更改时GetElementById的行为会有所不同,但我确实知道使用jquery进行此类操作要容易得多.再也没有人会像这样写代码了.
You debug these things in Chrome. You can see what is passed in, and see what your script looks like. I don''t know why GetElementById should behave differently when the style changes, but I do know that using jquery for this sort of stuff is a lot easier. No-one writes code like this anymore.


这篇关于第二次使用getElementById获取null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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