.html代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<style type="text/css">
#show{
width:100px;
height:100px;
margin:0 auto;
background:#2c2c2c;
color:#fff;
text-align:center;
}
</style>

<title>进制转换</title>
<script type="text/javascript">
document.write("<div id='show'>");
var data = parseInt(prompt("请输入十进制数据",1));//注意prompt函数
var base = parseInt(prompt("请输入进制基数(2,8,16)",2));
var result ;
switch(base){
case 2 :
case 8:
case 16 : result = data.toString(base);break;
default : result = "<span style='color:red'>非法</span>";

}
document.write(result);
documeng.write("</div>");
</script>
</head>
<body>
</body>
</html>

效果如下:

javascript小练习之进制转换_javascript

javascript小练习之进制转换_html_02

javascript小练习之进制转换_html_03