You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
807 B
19 lines
807 B
1 month ago
|
<script>
|
||
|
function convert() {
|
||
|
const inputNumber = document.getElementById("inputNumber").value;
|
||
|
const fromBase = parseInt(document.getElementById("fromBase").value);
|
||
|
const toBase = parseInt(document.getElementById("toBase").value);
|
||
|
|
||
|
try {
|
||
|
// 将输入的原进制数转换为10进制
|
||
|
const decimalValue = parseInt(inputNumber, fromBase);
|
||
|
// 将10进制数转换为目标进制
|
||
|
const convertedValue = decimalValue.toString(toBase).toUpperCase();
|
||
|
|
||
|
// 显示结果
|
||
|
document.getElementById("result").innerText = `转换结果 (Y): ${convertedValue}`;
|
||
|
} catch (error) {
|
||
|
document.getElementById("result").innerText = "转换失败,请确保输入正确。";
|
||
|
}
|
||
|
}
|
||
|
</script>
|