Compare commits
No commits in common. 'master' and 'main' have entirely different histories.
@ -1,26 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>进制转换器</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>进制转换器</h1>
|
||||
<label for="inputNumber">输入数字:</label>
|
||||
<input type="text" id="inputNumber" required>
|
||||
|
||||
<label for="fromBase">初始进制 (2-16):</label>
|
||||
<input type="number" id="fromBase" min="2" max="16" required>
|
||||
|
||||
<label for="toBase">目标进制 (2-16):</label>
|
||||
<input type="number" id="toBase" min="2" max="16" required>
|
||||
|
||||
<button onclick="convertBase()">转换</button>
|
||||
<p id="result"></p >
|
||||
</div>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -1,4 +0,0 @@
|
||||
212203252
|
||||
222222222
|
||||
dh333333333
|
||||
dh444444444
|
@ -1,28 +0,0 @@
|
||||
function convertBase() {
|
||||
const inputNumber = document.getElementById('inputNumber').value.trim();
|
||||
const fromBase = parseInt(document.getElementById('fromBase').value);
|
||||
const toBase = parseInt(document.getElementById('toBase').value);
|
||||
|
||||
// 验证输入数字是否符合fromBase的规则
|
||||
if (!isValidNumber(inputNumber, fromBase)) {
|
||||
alert('输入的数字无效!请检查其进制格式。');
|
||||
return;
|
||||
}
|
||||
|
||||
// 将输入的数字从fromBase转换为十进制
|
||||
const decimalValue = parseInt(inputNumber, fromBase);
|
||||
|
||||
// 将十进制数转换为toBase
|
||||
const result = decimalValue.toString(toBase).toUpperCase();
|
||||
document.getElementById('result').textContent = `转换结果: ${result}`;
|
||||
}
|
||||
|
||||
function isValidNumber(num, base) {
|
||||
const validChars = '0123456789ABCDEF'.slice(0, base);
|
||||
for (let char of num.toUpperCase()) {
|
||||
if (!validChars.includes(char)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f4f4f4;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 400px;
|
||||
margin: auto;
|
||||
padding: 20px;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin-top: 5px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
button {
|
||||
margin-top: 15px;
|
||||
padding: 10px;
|
||||
width: 100%;
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #218838;
|
||||
}
|
||||
|
||||
p {
|
||||
margin-top: 15px;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
}
|
Loading…
Reference in new issue