parent
b6613b884d
commit
7f25441fca
@ -1,28 +0,0 @@
|
||||
document.getElementById('convert-btn').addEventListener('click', function() {
|
||||
const number = document.getElementById('number-input').value;
|
||||
const base = document.getElementById('base-select').value;
|
||||
|
||||
let result = '';
|
||||
|
||||
if (!isNaN(number) && number.trim() !== '') {
|
||||
const decimalNumber = parseInt(number, 10);
|
||||
|
||||
switch (base) {
|
||||
case '2':
|
||||
result = decimalNumber.toString(2);
|
||||
break;
|
||||
case '8':
|
||||
result = decimalNumber.toString(8);
|
||||
break;
|
||||
case '16':
|
||||
result = decimalNumber.toString(16).toUpperCase();
|
||||
break;
|
||||
default:
|
||||
result = '请选择一个有效的进制';
|
||||
}
|
||||
} else {
|
||||
result = '请输入一个有效的数字';
|
||||
}
|
||||
|
||||
document.getElementById('result').textContent = result;
|
||||
});
|
Loading…
Reference in new issue