日期:2014-05-16  浏览次数:20376 次

JavaScript ---- 示例(十进制转换为二进制)
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>十进制转换为二进制</title>
    <script type="text/javascript">
      var input_digit = 0;
      var binary;
      function digit_to_binary()
      {
          input_digit = document.getElementById('input_digit').value
          binary = Number(input_digit).toString(2)
          alert("转换的二进制结果为: " + binary)
      }

    </script>
  </head>

  <body>
    <p>请输入一个合适的整数: 
      <input type="text"  value="0" id="input_digit"/>
      <input type="button" value="转换" onclick="digit_to_binary()" />
    </p>

  </body>
</html>