Compare commits

..

No commits in common. 'main' and '3c1eb19d67862d63eefd0ddee9c551664bfb19d2' have entirely different histories.

@ -1,2 +0,0 @@
# jhj_yzw

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Base Converter</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>进制转换器</h1>
<form id="converterForm">
<label for="inputValue">输入数值:</label>
<input type="text" id="inputValue" name="inputValue" required>
<label for="fromBase">原始进制2-16</label>
<input type="number" id="fromBase" name="fromBase" min="2" max="16" required>
<label for="toBase">目标进制2-16</label>
<input type="number" id="toBase" name="toBase" min="2" max="16" required>
<button type="submit">转换</button>
</form>
<div id="result"></div>
</div>
<script src="script.js"></script>
</body>
</html>

@ -1,15 +0,0 @@
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 = '转换错误,请检查输入是否正确';
}
});

@ -0,0 +1,25 @@
body {
font-family: Arial, sans-serif;
}
.container {
width: 300px;
margin: 50px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
form {
display: flex;
flex-direction: column;
}
label, input, button {
margin: 5px 0;
}
#result {
margin-top: 20px;
font-weight: bold;
}
Loading…
Cancel
Save