我从一个网站复制了一个多搜索脚本,我只更改了它告诉我的内容。然后,我将其另存为HTML文件并在Chrome中运行。但是当我输入一个单词并按回车键时,什么也没发生。我对计算机一无所知,所以我不知道从哪里开始
也不能在Explorer或Firefox上运行
<!DOCTYPE html>
<html>
<head>
</head>
<body style=”background-color:grey”>
<p>What German word would you like to multisearch? Type below, then press enter please.</p>
<input type=”text” id=”boxu” autofocus>
<script>
document.getElementById(“boxu”).onkeydown = function(e) {searchy(e)};
function searchy(e)
{
if (e.which == 13)
{
var q = document.getElementById(“boxu”).value;
window.open(“http://translate.google.com/translate?hl=en&sl=de&tl=en&u=http%3A%2F%2Fwww.google.de%2Fsearch%3Fq%3D” + q + “%26num%3D10%26hl%3Dde%26tbo%3Dd%26site%3Dimghp%26tbm%3Disch%26sout%3D1%26biw%3D1075%26bih%3D696”);
window.open(“http://www.forvo.com/word/” + q + “/#de”);
window.open(“https://de.wiktionary.org/wiki/” + q);
document.getElementById(“boxu”).value = “”;
}
}
</script>
</body>
</html>
答案 0 :(得分:0)
请尝试以下代码-
在onkeydown
输入中包含textbox
函数。在脚本中时,不会调用该函数。并且如注释所示,您在使用错误的“”。也修复了该问题。
<!DOCTYPE html>
<html>
<head>
</head>
<body style="background-color:grey">
<p>What German word would you like to multisearch? Type below, then press enter please.</p>
<input type="text" id="boxu" autofocus onkeydown="searchy(event)">
<script>
function searchy(e)
{
console.log(e)
if (e.keyCode == 13)
{
console.log("a");
var q = document.getElementById("boxu").value;
window.open("http://translate.google.com/translate?hl=en&sl=de&tl=en&u=http%3A%2F%2Fwww.google.de%2Fsearch%3Fq%3D" + q + "%26num%3D10%26hl%3Dde%26tbo%3Dd%26site%3Dimghp%26tbm%3Disch%26sout%3D1%26biw%3D1075%26bih%3D696");
window.open("http://www.forvo.com/word/" + q + "/#de");
window.open("https://de.wiktionary.org/wiki/" + q);
document.getElementById("boxu").value = "";
}
}
</script>
</body>
</html>