当我使用if和else单击单选按钮时,我想显示文本框

时间:2014-05-13 09:07:40

标签: javascript html

function show() { document.getElementById('debit').style.display = 'block'; }
function hide() { document.getElementById('credit').style.display = 'none'; }

如果我点击借记单选按钮显示借记文本框并使信用文本框消失,如果我点击信用单选按钮,则自动消失借方文本框,默认情况下消失两个文本框,下面是我的HTML。

<INPUT TYPE=RADIO NAME="num" VALUE="debit" onclick="hide();"/>A 
<INPUT TYPE=RADIO NAME="num" VALUE="credit" onclick="show();"/>B 

<input type="number" id="debit" name="debit" placeholder="debit">
<input type="number" id="credit" name="credit" placeholder="credit">

1 个答案:

答案 0 :(得分:0)

也许你在找这样的东西?

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8" />
  <title></title>
  <script type="text/javascript">
    function init() {
      document.getElementById('debit').style.display = 'none';
      document.getElementById('credit').style.display = 'none';
    }
    function showDebit() { document.getElementById('credit').style.display = 'none'; document.getElementById('debit').style.display = 'block'; }
    function showCredit() { document.getElementById('credit').style.display = 'block'; document.getElementById('debit').style.display = 'none'; }
  </script>
</head>
<body onload="init()">
  <input type="RADIO" name="num" value="debit" onclick="showDebit();" />A 
  <input type="RADIO" name="num" value="credit" onclick="showCredit();" />B 

  <input type="number" id="debit" name="debit" placeholder="debit">
  <input type="number" id="credit" name="credit" placeholder="credit">


</body>
</html>