源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <h2>JavaScript二进制转换为十进制</h2> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = dec2bin(101); function dec2bin(bin){ return parseInt(bin, 2).toString(10); } </script> </body> </html>
运行结果