我的网站中有一个简单的 javascript 搜索功能,效果很好,但是,在点击 Enter 后,它会在页面下方加载一些产品页面。我无法深究。这是我构建的 javascript 搜索功能的一些示例代码。如果您想测试,有问题的页面是https://black-rhodium.co.uk/Products
我已经把右下角的聊天机器人功能拿出来测试了,没什么区别。
控制台/源(歌剧)中没有错误。
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=0, minimum-
scale=1.0, maximum-scale=1.0">
<title>Tuto</title>
</head>
<body style=" background-color: rgb(4, 41, 255);">
<input type="search" autocomplete="off" value="" placeholder="Search here..." id="search"
onchange="openPage()">
<script>
function openPage() {
var x = document.getElementById("search").value;
if (x.toLowerCase() === "Wave".toLowerCase()) {
window.top.location = ("/Products#!/products/wave-usb---dealer-only---click-for-more-info");
}
if (x.toLowerCase() === "Wave USB".toLowerCase()) {
window.top.location = ("/Products#!/products/wave-usb---dealer-only---click-for-more-info");
}
if (x.toLowerCase() === "Waltz links".toLowerCase()) {
window.top.location = ("/Products#!/products/waltz-speaker-links");
}
if (x.toLowerCase() === "Waltz speakerlinks".toLowerCase()) {
window.top.location = ("/Products#!/products/waltz-speaker-links");
}
}
</script>
</body>