隐形DIV不可用于JavaScript [英] Invisible DIV not available to JavaScript
问题描述
我敢肯定的回答我的问题是这里的某个地方,但我无法找到它。我很抱歉,如果我重复。
我根据我拉回来的数据有我设置它的可视性页面加载一个DIV。
因此,在code背后:
this.divMyDiv.Visible = FALSE
如果用户然后更改下拉值我试图展现DIV
DIV VAR =的document.getElementById('divMyDiv');
div.style.display =块;
如果在div被设置为可见由code背后的初始页面加载所有的罚款。该DIV将显示和隐藏当我改变下拉值。然而,当DIV是隐藏在页面加载在JavaScript中的无功格总是空。我曾尝试 DIV VAR =的document.getElementById('<%= divMyDiv.ClientID%GT;');
,但我得到了相同的结果。我也曾尝试移动JS到页面的底部。相同的结果。
this.divMyDiv.Visible = FALSE
... ...将prevent股利从根本上被渲染和JavaScript无法找到它。如果你仍然想渲染它,并使用显示:无
来隐藏它,你会想要做的;
this.divMyDiv.Style [显示] =无;
Im sure the answer to my question is here somewhere but I cannot find it. I apologise if I have duplicated.
I have a DIV that I set its visiblity on page load depending on the data I pull back.
So in the code behind:
this.divMyDiv.Visible = false
If the user then changes a drop down value I try to show the DIV
var div = document.getElementById('divMyDiv');
div.style.display = 'block';
If the div is set to visible by the code behind on the initial page load all is fine. The DIV will show and hide when I change the drop down value. However when the DIV is hidden on page load the var div in the JavaScript is always null. I have tried var div = document.getElementById('<%=divMyDiv.ClientID%>');
but I get the same results. I have also tried moving the JS to the bottom of the page. Same results.
this.divMyDiv.Visible = false
...will prevent the div from being rendered at all and Javascript can't find it. If you still want to render it and use display:none
to hide it, you'll want to do;
this.divMyDiv.Style["display"] = "none";
这篇关于隐形DIV不可用于JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!