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.
15 lines
760 B
15 lines
760 B
1 month ago
|
document.getElementById('converterForm').addEventListener('submit', function(event) {
|
||
|
event.preventDefault(); // 阻止表单默认提交行为
|
||
|
|
||
|
const inputValue = document.getElementById('inputValue').value.toUpperCase();
|
||
|
const fromBase = parseInt(document.getElementById('fromBase').value, 10);
|
||
|
const toBase = parseInt(document.getElementById('toBase').value, 10);
|
||
|
|
||
|
try {
|
||
|
const decimalValue = parseInt(inputValue, fromBase);
|
||
|
const result = decimalValue.toString(toBase).toUpperCase();
|
||
|
document.getElementById('result').textContent = `转换后的数值:${result} (${toBase}进制)`;
|
||
|
} catch (e) {
|
||
|
document.getElementById('result').textContent = '转换错误,请检查输入是否正确';
|
||
|
}
|
||
|
});
|