摩斯电码翻译器在线转换下载
body {
fontfamily: Arial, sansserif;
margin: 0;
padding: 20px;
}
h1 {
textalign: center;
marginbottom: 30px;
}
form {
display: flex;
flexdirection: column;
width: 100%;
}
label {
marginbottom: 5px;
}
input[type="text"], textarea {
width: 100%;
padding: 10px;
marginbottom: 15px;
}
button {
backgroundcolor: 4CAF50;
color: white;
padding: 10px 20px;
border: none;
cursor: pointer;
borderradius: 5px;
}
.result {
margintop: 20px;
padding: 20px;
border: 1px solid ccc;
borderradius: 5px;
backgroundcolor: f2f2f2;
}
.output {
fontweight: bold;
}
在线摩斯电码翻译器
// 摩斯电码翻译逻辑
function decodeMorse(morseCode) {
// 假设你已经有了一个完整的摩斯电码到文本的映射表
// 这里我们提供一个基础的示例,实际应用中可能需要从服务器获取
const morseTable = {
'.': 'A',
'..': 'B',
'.': 'C',
'....': 'D',
'...': 'E',
'..': 'F',
'..': 'G',
'..': 'H',
'....': 'I',
'..': 'J',
'.': 'K',
'.': 'L',
'...': 'M',
'': 'N',
'.': 'O',
'': 'P',
'..': 'Q',
'.': 'R',
'..': 'S',
'...', ' ': ' '
};
let decoded = '';
morseCode.split(' ').forEach(char => {
if (morseTable[char]) {
decoded = morseTable[char];
}

});
return decoded;
}
document.getElementById('morseDecoderForm').addEventListener('submit', async (e) => {
e.preventDefault();
const input = document.getElementById('morseInput').value || document.getElementById('textInput').value;
let decodedText;
if (input.startsWith('.')) { // 检查是否为摩斯电码
decodedText = decodeMorse(input);
} else {
decodedText = input; // 假设输入的是已经转换过的文本
}
document.getElementById('resultArea').innerHTML = `
${decodedText}
`;});