han 4 months ago
parent e96c3e6d71
commit e264aec8d1

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>进制转换</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 10px;
max-width: 400px;
}
label, input, button {
display: block;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h2>任意进制转换器</h2>
<label for="fromBase">输入进制 (2-16):</label>
<input type="number" id="fromBase" min="2" max="16" required>
<label for="number">输入数字:</label>
<input type="text" id="number" required>
<label for="toBase">转换为进制 (2-16):</label>
<input type="number" id="toBase" min="2" max="16" required>
<button id="convertButton">转换</button>
<h3>结果:</h3>
<div id="result"></div>
<script>
document.getElementById('convertButton').addEventListener('click', function() {
const fromBase = parseInt(document.getElementById('fromBase').value);
const number = document.getElementById('number').value;
const toBase = parseInt(document.getElementById('toBase').value);
// 先将输入的任意进制数转换为十进制
const decimalValue = parseInt(number, fromBase);
// 将十进制数转换为目标进制
const convertedValue = decimalValue.toString(toBase).toUpperCase();
// 显示结果
document.getElementById('result').textContent = convertedValue;
});
</script>
</body>
</html>

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>进制转换</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 10px;
max-width: 400px;
}
label, input, button {
display: block;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h2>任意进制转换器</h2>
<label for="fromBase">输入进制 (2-16):</label>
<input type="number" id="fromBase" min="2" max="16" required>
<label for="number">输入数字:</label>
<input type="text" id="number" required>
<label for="toBase">转换为进制 (2-16):</label>
<input type="number" id="toBase" min="2" max="16" required>
<button id="convertButton">转换</button>
<h3>结果:</h3>
<div id="result"></div>
<script>
document.getElementById('convertButton').addEventListener('click', function() {
const fromBase = parseInt(document.getElementById('fromBase').value);
const number = document.getElementById('number').value;
const toBase = parseInt(document.getElementById('toBase').value);
// 先将输入的任意进制数转换为十进制
const decimalValue = parseInt(number, fromBase);
// 将十进制数转换为目标进制
const convertedValue = decimalValue.toString(toBase).toUpperCase();
// 显示结果
document.getElementById('result').textContent = convertedValue;
});
</script>
</body>
</html>
Loading…
Cancel
Save