vb.net 使用javascript可见的文本框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19721940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:41:16  来源:igfitidea点击:

Text box visible using javascript

javascriptasp.netvb.net

提问by abcd shsu

I have a hidded textbox and Imagebutton.For avoiding the Postback i am trying to make textbox visible on click of the image button using javascript.But textbox is not showing on click of the image button,Instead image btton is moving. What could be wrong here in this code.

我有一个隐藏的文本框和图像按钮。为了避免回发,我试图使用 javascript 在单击图像按钮时使文本框可见。但是单击图像按钮时没有显示文本框,而是图像 btton 正在移动。这段代码中可能有什么问题。

Appreciate ur help

感谢您的帮助

  <asp:TextBox ID="TextBox2" text="From:" style=" visibility: hidden"  runat="server"  BackColor="#999999" BorderColor="Black" BorderStyle="Double"></asp:TextBox>

 <asp:ImageButton ID="ImageButton2" runat="server" BackColor="#99CCFF" 
 BorderColor="#84C1FF" BorderStyle="Outset" OnClientClick="MJavascriptFunction();return false;"  Height="35px" 
ImageUrl="search11.png" Width="56px" />

<script type="text/javascript">

   function MJavascriptFunction(obj) {
       var theControl = document.getElementById("<%=Textbox2.ClientID %>");

       theControl.style.display = "block";

   }

  </script>

回答by MarsOne

Change

改变

theControl.style.display = "block";

To

theControl.style.visibility="visible";

Example

例子

In your Code you set the visiblity option to "hidden", So you need to use the same property in javscript

在您的代码中,您将可见性选项设置为“隐藏”,因此您需要在 javscript 中使用相同的属性

Alternatively you can change the HTML inline CSS to style="display:none".

或者,您可以将 HTML 内联 CSS 更改为 style="display:none"。

Example

例子