在javascript中访问不可见控件 [英] accessing invisible control in javascript

查看:74
本文介绍了在javascript中访问不可见控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我该如何使用JavaScript来访问不可见控件,例如
label

hi all , how can i access invisible control using javascript such that
label

推荐答案

您必须使用 display 样式来处理它.

您无法通过javascript访问不可见的控件.只有在客户端站点上呈现的控件才可用于javascript.

如果在服务器端将特定控件标记为Visible=false ,则该控件将不再出现在客户端计算机上呈现的页面的HTML中.

尽管还有另一种方法来处理这种情况.如果您需要隐藏一个控件但又想用Javascript访问它,则可以使用style:display属性.

因此:
隐藏 控件
You have to use display style to handle it.

You cannot access invisible controls via javascript. Only those controls that are rendered on client site are available to javascript.

If a particular control is marked as Visible=false at server side, then that control is no more present in the HTML of the rendered page on client machine.

Though there is another way to handle such scenarios. If you need to hide a control but also want to access it in Javascript then play with style:display property.

Thus:
to hide the control
// javascript code
document.getElementById("<%=lblToHide.ClientID%>").style.display = "none";



显示控件



to show the control

//javascript code
document.getElementById("<%=lblToHide.ClientID%>").style.display = "block";


您可以按照以下技巧进行操作.不要为控件设置visible ="false",只需为控件使用样式属性(显示)即可.
例子.
You can do that by following trick. Don''t set visible="false" to your control, just use the style property(display) for the control.
example.
<input type="text" text="Hello" name="txtInvisible" style="display:none;" />


alert(document.getElementById('txtInvisible').value)


这篇关于在javascript中访问不可见控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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