请帮助我,为什么内容页面中的此javascript代码不起作用. [英] help me please , why this javascript code in content page not work .
本文介绍了请帮助我,为什么内容页面中的此javascript代码不起作用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script language="javascript" type="text/javascript">
function chvisible(controlId)
{
var control = document.getElementById(controlId);
if(control.style.visibility == "visible" || control.style.visibility == "")
control.style.visibility = "hidden";
else
control.style.visibility = "visible";
}
</script>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input id="Button1" type="button" value="button" onclick="chvisible('TextBox1');"/>
</asp:Content>
推荐答案
而不是control.style.visibility
,请尝试control.style.display
要切换显示,请使用阻止"& "none"作为两个值.
样式的Display属性可以隐藏控件,但仍可在需要时保留页面上的控件以在需要时访问客户端.
Instead ofcontrol.style.visibility
, try,control.style.display
For toggling display, use ''block'' & ''none'' as the two values.
Display property of the style hides the control and yet keeps the control on page to access client side when needed.
hello,
另外,请尝试使用
< input id ="Button1" type ="button" value ="button" onclick ="chvisible(''<%= TextBox1.ClientID%>'');" />
代替
< input id ="Button1" type ="button" value ="button" onclick ="chvisible(" TextBox1);"/>
hello,
Also, try use
<input id="Button1" type="button" value="button" onclick="chvisible(''<%=TextBox1.ClientID %>'');"/>
instead of
<input id="Button1" type="button" value="button" onclick="chvisible(''TextBox1'');"/>
这篇关于请帮助我,为什么内容页面中的此javascript代码不起作用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文