单击按钮时隐藏并显示文本字段

问题描述

我想知道单击按钮时如何隐藏和显示文本字段。我已经在HTML和CSS上创建了一个类,其中隐藏了我想要的文本字段,因此我只需要知道如何执行它并在单击按钮时显示它即可。

这是我的代码

HTML

</head>
<body>
<div class="container">
  <h2 class="text-center">List</h2>

       
  <input type="text" id="txt" name="txt" onclick="this.value = '' "/>
  <button onclick="getAndSetVal();" id="button">Add List</button>
  <input type="text" id="txt2" class="hide" name="txt" onclick="this.value = '' "/>
  
     
  

</div>
<body>
<html>

JS

<script>
         
         
            
            function getAndSetVal()
            {
                var txt1 = document.getElementById('txt').value;
                document.getElementById('txt2').value = txt1;
            }
            
          
            function getVal()
            {
             var txt = document.getElementById('txt').value;
             alert(txt);
            }
            
        </script>
        

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)