以下是我的密码。它由三个按钮和一个显示屏组成。
<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,则不会显示任何内容。如果你按下显示和按1,那么1将显示在屏幕上。
可能的方法是只是禁用1按钮,如果你点击隐藏,但我仍然希望用户能够点击按钮后,按下隐藏,而不是显示任何东西。
我是JS的新手,所以如果这是个糟糕的问题,请原谅。
发布于 2014-10-30 18:07:56
我会将所有的js封装在<script>中,以便能够使用vars。
<script>
var hide = 0;
function appendChar(){
if(hide==0){
document.fun.ans.value+='1';
}
}
</script>然后我们必须修改html:
<input type="button" value="1" onClick="appendChar()">
<input type="button" value="hide" onclick="hide=1;">
<input type="button" value="show" onclick="hide=0;">发布于 2014-10-30 18:04:41
使用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>https://stackoverflow.com/questions/26660101
复制相似问题