<div class="codetitle"> <span><a style="CURSOR: pointer" data="9394" class="copybut" id="copybut9394" onclick="doCopy('code9394')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code9394"> <br> <br> <br> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br><title>10进制2进制</title> <br> <br><br> <br>Decimal: <br> <input type="text" id="decimal"> <br> <input type="button" value="to Binary" onclick="return toBinary();"> <br> <br>Binary: <br> <input type="text" id="binary"> <br> <input type="button" value="to Decimal" onclick="return toDecimal();"> <br><br> <br><script type="text/javascript"> <BR>var d = document.getElementById('decimal'); <BR>var b = document.getElementById('binary'); <br><br>function toBinary() { <BR> var num = d.value; <BR> if (isNaN(num) || !num) { <BR> d.value = ""; <BR> return false; <BR> } <BR> b.value = (parseInt(num)).toString(2); <BR>} <br><br>function toDecimal() { <BR> var num = b.value; <BR> if (isNaN(num) || !num) { <BR> b.value = ""; <BR> return false; <BR> } <BR> d.value = parseInt(num, 2); <BR>} <BR></script> <br> <br> <br> </div>