first commit
This commit is contained in:
commit
7d9a5d4616
50
1.html
Normal file
50
1.html
Normal file
@ -0,0 +1,50 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>电容值转换</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>电容值转换工具</h1>
|
||||
<label for="capInput">输入电容值:</label>
|
||||
<input type="text" id="capInput" placeholder="输入电容值">
|
||||
<button onclick="convertCap()">转换</button>
|
||||
<p id="output">转换结果将在这里显示</p>
|
||||
|
||||
<script>
|
||||
function cap_namer(value_str) {
|
||||
value_str = value_str.toLowerCase();
|
||||
if (value_str.includes('u')) {
|
||||
base = 1000000;
|
||||
} else if (value_str.includes('n')) {
|
||||
base = 1000;
|
||||
} else if (value_str.includes('p')) {
|
||||
base = 1;
|
||||
} else {
|
||||
throw '错误的值';
|
||||
}
|
||||
value_flt = parseFloat(value_str);
|
||||
inner_flt = value_flt * base;
|
||||
if (inner_flt < 10) {
|
||||
code = inner_flt.toString().replace('.', 'R');
|
||||
} else {
|
||||
code = inner_flt.toString().slice(0, 2) + (inner_flt.toString().length - 4);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
function convertCap() {
|
||||
const inputElement = document.getElementById("capInput");
|
||||
const inputValue = inputElement.value;
|
||||
const outputElement = document.getElementById("output");
|
||||
|
||||
try {
|
||||
const convertedValue = cap_namer(inputValue);
|
||||
outputElement.textContent = "转换结果:" + convertedValue;
|
||||
} catch (error) {
|
||||
outputElement.textContent = "错误:" + error;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
99
2.html
Normal file
99
2.html
Normal file
@ -0,0 +1,99 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>电容/电阻值转换</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>电容/电阻值转换工具</h1>
|
||||
<label for="typeSelect">选择类型:</label>
|
||||
<select id="typeSelect">
|
||||
<option value="capacitance">电容</option>
|
||||
<option value="resistance">电阻</option>
|
||||
</select>
|
||||
<br><br>
|
||||
<label for="valueInput">输入值:</label>
|
||||
<input type="text" id="valueInput" placeholder="输入电容/电阻值" onkeydown="handleKeyDown(event)">
|
||||
<button onclick="convertValue()">转换</button>
|
||||
<p id="output">转换结果将在这里显示</p>
|
||||
|
||||
<script>
|
||||
function cap_namer(value_str) {
|
||||
value_str = value_str.toLowerCase();
|
||||
if (value_str.includes('u')) {
|
||||
base = 1000000;
|
||||
} else if (value_str.includes('n')) {
|
||||
base = 1000;
|
||||
} else if (value_str.includes('p')) {
|
||||
base = 1;
|
||||
} else {
|
||||
throw '错误的值';
|
||||
}
|
||||
value_flt = parseFloat(value_str);
|
||||
inner_flt = value_flt * base;
|
||||
if (inner_flt < 10) {
|
||||
code = inner_flt.toString().replace('.', '');
|
||||
} else {
|
||||
code = inner_flt.toString().slice(0, 2) + (inner_flt.toString().length - 4);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
function res_namer(value_str) {
|
||||
value_str = value_str.toLowerCase();
|
||||
if (value_str.includes('k')) {
|
||||
base = 1000;
|
||||
} else if (value_str.includes('m')) {
|
||||
base = 1000000;
|
||||
} else if (value_str.includes('g')) {
|
||||
base = 1000000000;
|
||||
} else if (value_str.includes('r')) {
|
||||
base = 1;
|
||||
} else {
|
||||
throw '错误的值';
|
||||
}
|
||||
value_flt = parseFloat(value_str);
|
||||
inner_flt = value_flt * base;
|
||||
if (inner_flt < 1 && inner_flt > 0) {
|
||||
inner_flt=inner_flt*10
|
||||
code = "0"+"R"+inner_flt.toString().replace('.', '');
|
||||
}
|
||||
else if (inner_flt < 10 && inner_flt > 1) {
|
||||
code = inner_flt.toString().replace('.', '');
|
||||
} else {
|
||||
code = inner_flt.toString().slice(0, 2) + (inner_flt.toString().length - 2);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
function convertValue() {
|
||||
const typeSelect = document.getElementById("typeSelect");
|
||||
const valueInput = document.getElementById("valueInput");
|
||||
const outputElement = document.getElementById("output");
|
||||
const valueType = typeSelect.value;
|
||||
const inputValue = valueInput.value;
|
||||
|
||||
try {
|
||||
let convertedValue;
|
||||
if (valueType === "capacitance") {
|
||||
convertedValue = "C" + cap_namer(inputValue);
|
||||
} else if (valueType === "resistance") {
|
||||
convertedValue = "R" + res_namer(inputValue);
|
||||
}
|
||||
outputElement.textContent = "转换结果:" + convertedValue;
|
||||
} catch (error) {
|
||||
outputElement.textContent = "错误:" + error;
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeyDown(event) {
|
||||
if (event.key === "Enter") {
|
||||
convertValue();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
109
3.html
Normal file
109
3.html
Normal file
@ -0,0 +1,109 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>电容/电阻值转换</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>电容/电阻值转换工具</h1>
|
||||
|
||||
<label for="typeSelect">选择类型:</label>
|
||||
<select id="typeSelect">
|
||||
<option value="capacitance">电容</option>
|
||||
<option value="resistance">电阻</option>
|
||||
<option value="ic">IC</option>
|
||||
</select>
|
||||
<br><br>
|
||||
|
||||
<label for="footprintSelect">选择封装:</label>
|
||||
<select id="footprintSelect">
|
||||
<option value="sot">电容</option>
|
||||
<option value="dip">电阻</option>
|
||||
<option value="0603">0603</option>
|
||||
</select>
|
||||
<br><br>
|
||||
<label for="valueInput">输入值:</label>
|
||||
<input type="text" id="valueInput" placeholder="输入电容/电阻值" onkeydown="handleKeyDown(event)">
|
||||
<button onclick="convertValue()">转换</button>
|
||||
<p id="output">转换结果将在这里显示</p>
|
||||
|
||||
<script>
|
||||
function cap_namer(value_str) {
|
||||
value_str = value_str.toLowerCase();
|
||||
if (value_str.includes('u')) {
|
||||
base = 1000000;
|
||||
} else if (value_str.includes('n')) {
|
||||
base = 1000;
|
||||
} else if (value_str.includes('p')) {
|
||||
base = 1;
|
||||
} else {
|
||||
throw '错误的值';
|
||||
}
|
||||
value_flt = parseFloat(value_str);
|
||||
inner_flt = value_flt * base;
|
||||
if (inner_flt < 10) {
|
||||
code = inner_flt.toString().replace('.', '');
|
||||
} else {
|
||||
code = inner_flt.toString().slice(0, 2) + (inner_flt.toString().length - 4);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
function res_namer(value_str) {
|
||||
value_str = value_str.toLowerCase();
|
||||
if (value_str.includes('k')) {
|
||||
base = 1000;
|
||||
} else if (value_str.includes('m')) {
|
||||
base = 1000000;
|
||||
} else if (value_str.includes('g')) {
|
||||
base = 1000000000;
|
||||
} else if (value_str.includes('r')) {
|
||||
base = 1;
|
||||
} else {
|
||||
throw '错误的值';
|
||||
}
|
||||
value_flt = parseFloat(value_str);
|
||||
inner_flt = value_flt * base;
|
||||
if (inner_flt < 1 && inner_flt > 0) {
|
||||
inner_flt=inner_flt*10
|
||||
code = "0"+"R"+inner_flt.toString().replace('.', '');
|
||||
}
|
||||
else if (inner_flt < 10 && inner_flt > 1) {
|
||||
code = inner_flt.toString().replace('.', '');
|
||||
} else {
|
||||
code = inner_flt.toString().slice(0, 2) + (inner_flt.toString().length - 2);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
function convertValue() {
|
||||
const typeSelect = document.getElementById("typeSelect");
|
||||
const valueInput = document.getElementById("valueInput");
|
||||
const outputElement = document.getElementById("output");
|
||||
const valueType = typeSelect.value;
|
||||
const inputValue = valueInput.value;
|
||||
|
||||
try {
|
||||
let convertedValue;
|
||||
if (valueType === "capacitance") {
|
||||
convertedValue = "C" + "-" + cap_namer(inputValue);
|
||||
} else if (valueType === "resistance") {
|
||||
convertedValue = "R" + "-" + res_namer(inputValue);
|
||||
}
|
||||
outputElement.textContent = "转换结果:" + convertedValue;
|
||||
} catch (error) {
|
||||
outputElement.textContent = "错误:" + error;
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeyDown(event) {
|
||||
if (event.key === "Enter") {
|
||||
convertValue();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user