如何访问JavaScript中的隐藏控件 [英] How to acess hidden controls in javascript

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

问题描述

通常在asp.net中,将控件的可见性设置为false时.那么该控件在呈现时将不会显示在aspx页面中.该控件及其值不适用于任何javascript函数,因为未呈现该控件.

Usually in asp.net, when you set the visibility of a control as false. then that control will not be shown in the aspx page when it renders. The control and its value is not available for any javascript function since the control is not rendered.

dropdown1.Visibility = False;


举例来说,存在一个带有值的下拉列表,并且控件的可见性为false.
但是我希望控件的选定值在javascript函数内执行一些验证.
有什么方法可以访问javascript中隐藏的控件的ID或值.

[条件:不应使用任何隐藏字段来存储隐藏控件的值]


Say for example there is a dropdown with a value and the control visibility is false.
But i want the control''s selected value to perform some validation inside a javascript function.
Is there any way to access the hidden control''s id or value in javascript.

[Condition : No hidden field should be used to store the hidden control''s value]

推荐答案

好吧,您可以轻松地解决此问题.

您必须做的是将"Visible = false"用作下拉列表中的属性之一.这不仅会隐藏,而且还会使控件不参与页面渲染.它将完全丢失,因此即使通过JavaScript也无法访问.

相反,使用样式显示属性,一切都会很好.
Well, you can easily workout on this issue.

What you must have done is used ''Visible=false'' as one of the attribute on dropdown. This would not just hide but also let the control not participate in page rendering. It will be completely missing and thus no accessibility even via JavaScript.

Instead, use style display property and all will be good.
//server side codes
myDropdown.Style.Add("display","none") // hides it but accessible via JS  

myDropdown.Style.Add("display","block") //shows it back


在JS中,只需传递ID,您就可以访问要播放的控件.

试试吧!


In JS, just pass on the ID and you will get access to the control to play.

Try!


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

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