如何通过单击建议栏上的单词来翻译完成建议?
我只能在此项目中使用HTML,CSS和JavaScript。该应用是翻译器。我做了大部分内容,但是我在翻译建议中选择的单词有问题(我确实在JavaScript上创建了建议),当我独自列出文本时,它会翻译该文本,但是IDK如何通过在建议部分中选择它,将不胜感激。 HTML代码在下面。
function checkfortranslate(){
var input = document.getElementById("input").value;
var output = document.getElementById("output");
input = input.toLowerCase();
if(input=="able"){
output.innerHTML = "привет";
}
else if(input=="about"){
output.innerHTML = "привет";
}
else if(input=="allow"){
output.innerHTML = "привет";
}
else if(input=="above"){
output.innerHTML = "благодарю вас";
}
else if(input=="abroad"){
output.innerHTML = "привет";
}
else if(input=="accident"){
output.innerHTML = "привет";
}
}
<h2>SIMPLE ENGLISH TRANSLATOR</h2>
<form autocomplete="off">
<div>
<input id="input" type="text" placeholder="Write text to translate" onkeyup="checkfortranslate()">
<ul class="list"></ul>
<div id="output" style="display: inline;">[Translation]</div>
</div>
</form>
I can only use HTML, CSS, and Javascript for this project. The app is a translator. I did most of it, but I have a problem with translating the word which I select in the suggestions (I did create suggestion thing on javascript), it translates the text when I put it on my own, but idk how to do it by selecting it on the suggestion part, any help would be appreciated. HTML code is below.
function checkfortranslate(){
var input = document.getElementById("input").value;
var output = document.getElementById("output");
input = input.toLowerCase();
if(input=="able"){
output.innerHTML = "привет";
}
else if(input=="about"){
output.innerHTML = "привет";
}
else if(input=="allow"){
output.innerHTML = "привет";
}
else if(input=="above"){
output.innerHTML = "благодарю вас";
}
else if(input=="abroad"){
output.innerHTML = "привет";
}
else if(input=="accident"){
output.innerHTML = "привет";
}
}
<h2>SIMPLE ENGLISH TRANSLATOR</h2>
<form autocomplete="off">
<div>
<input id="input" type="text" placeholder="Write text to translate" onkeyup="checkfortranslate()">
<ul class="list"></ul>
<div id="output" style="display: inline;">[Translation]</div>
</div>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用html datalists 元素。
编辑:
You can use html datalist element.
Edit: