<input type = "input" id="original" />
<input type = "button" onclick = change10() value = "从10进制转换" />
<input type = "button" onclick = change2() value = "从2进制转换" />
<input type = "button" onclick = change8() value = "从8进制转换" />
<input type = "button" onclick = change16() value = "从16进制转换" />
<script>
var oOriginal = document.getElementById("original");
function change10(){
var num = parseInt(oOriginal.value);
alert("2: " + num.toString(2) + "/n" + "8: " + num.toString(8) + "/n" + "10: " + num.toString(10) + "/n" + "16: " + num.toString(16));
}
function change2(){
var num = parseInt(oOriginal.value,2);
alert("2: " + num.toString(2) + "/n" + "8: " + num.toString(8) + "/n" + "10: " + num.toString(10) + "/n" + "16: " + num.toString(16));
}
function change8(){
var num = parseInt(oOriginal.value,8);
alert("2: " + num.toString(2) + "/n" + "8: " + num.toString(8) + "/n" + "10: " + num.toString(10) + "/n" + "16: " + num.toString(16));
}
function change16(){
var num = parseInt(oOriginal.value,16);
alert("2: " + num.toString(2) + "/n" + "8: " + num.toString(8) + "/n" + "10: " + num.toString(10) + "/n" + "16: " + num.toString(16));
}
</script>
javascript十进制、二进制、八进制、十六进制转换(转别人的)
最新推荐文章于 2024-09-02 18:54:41 发布