diff --git a/change——javascript.js b/change——javascript.js new file mode 100644 index 0000000..42507da --- /dev/null +++ b/change——javascript.js @@ -0,0 +1,28 @@ +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; +}); \ No newline at end of file