Javascript 显示或隐藏通过单击显示的信息

Javascript 显示或隐藏通过单击显示的信息,javascript,html,Javascript,Html,下面是我的代码。它由三个按钮和一个显示屏组成 <html> <head> <script type="text/javascript"> </script> </head> <body> <form name="fun" > Display Screen<input type="textfield" name="ans" value=""> <br> <input type="b

下面是我的代码。它由三个按钮和一个显示屏组成

<html>
<head>
<script type="text/javascript">


</script>
</head>
<body>
<form name="fun" >
Display Screen<input type="textfield" name="ans" value="">
<br>
<input type="button" value="1" onClick="document.fun.ans.value+='1'">
<input type="button" value="hide">
<input type="button" value="show">


</form>
</body>
</html>

显示屏

当前,当您按下1时,它将在显示屏上显示1。 我想实现一个功能,这样,如果你点击隐藏,然后按1,什么都不会得到显示。如果按show并按1,屏幕上将显示1

可能的方法是,只要禁用1按钮,如果你点击隐藏,但我仍然希望用户能够点击按钮后,按下隐藏只是不显示任何东西


我是JS新手,如果这是一个糟糕的问题,请原谅。

使用javascript显示和隐藏元素的示例:

<html>
<head>
<script type="text/javascript">


</script>
</head>
<body>
<form name="fun" >
Display Screen<input id="ans" type="textfield" name="ans" value="">
<br>
<input type="button" value="1" onClick="document.fun.ans.value='1'">
<input type="button" value="hide" onclick="hide()">
<input type="button" value="show" onclick="show()">

<script type="text/javascript">
function hide()
{
   document.getElementById("ans").style.display = "none";
}
function show()
{
   document.getElementById("ans").value = '';
   document.getElementById("ans").style.display = "inline-block";
}
</script>


</form>
</body>
</html>

显示屏

函数hide() { document.getElementById(“ans”).style.display=“无”; } 函数show() { document.getElementById(“ans”).value=''; document.getElementById(“ans”).style.display=“内联块”; }
为了能够使用vars,我将所有的js包装在

<script>
    var hide = 0;
    function appendChar(){
        if(hide==0){
            document.fun.ans.value+='1';
        }
    }

</script>

var=0;
函数appendChar(){
如果(隐藏==0){
document.fun.ans.value+='1';
}
}
然后我们必须修改html:

<input type="button" value="1" onClick="appendChar()">
<input type="button" value="hide" onclick="hide=1;">
<input type="button" value="show" onclick="hide=0;">


看看我的答案,我想这就是你想要的……希望它能帮上忙!您的意思是,如果已经单击“隐藏”,则不应在单击“1”时追加任何内容(如果已经单击“显示”,则在单击“1”时追加1)?还是完全隐藏文本字段?