具体化搜索,自动完成.如何根据所选选项更改站点?



我最近对Materialize产生了兴趣,并尝试用它做一个项目,但我正在努力使用自动完成功能更改站点。

我正在做一个旅行社网站,例如,如果有人选择巴哈马,我希望它去巴哈马.html如果有人选择巴厘岛来巴利弗.html。

我在文档中看到您可以使用 onAutocomplete 选项,每当有人使用自动完成时都会触发一个函数,但我只是不知道我应该在那里传递什么参数。

我大致知道我想做什么,但我需要所选内容的内部文本,我不知道如何将该对象传递给使用 onAutocomplete 运行的函数。

我尝试阅读源代码并自己弄清楚,但我是初学者,现在对我来说太复杂了。

我将发布一些代码供您获得更好的见解。

现在它所做的只是用户选择什么,它将网站更改为"balioferta.html"。

const autoComplete = document.querySelectorAll('.autocomplete');
M.Autocomplete.init(autoComplete, {
data: {
"Bali": null,
"Bahama": null,
"Wyspy Kanaryjskie": null,
"Ibiza": null,
"Madagaskar": null,
"Australia": null,
"Polska": null,
"Tybet": null
},
limit: 5,
minLength: 2,
onAutocomplete: () => {
window.location = 'balioferta.html';
}
});

我自己解决了,这真的很简单。我所要做的就是提出一个论点。

如果有人遇到此问题,以供将来参考。

const autoComplete = document.querySelectorAll('.autocomplete');
M.Autocomplete.init(autoComplete, {
data: {
"Bali": null,
"Bahama": null,
"Wyspy Kanaryjskie": null,
"Ibiza": null,
"Madagaskar": null,
"Australia": null,
"Polska": null,
"Tybet": null
},
limit: 5,
minLength: 2,
onAutocomplete: (res) => {
let siteHTML = res.toLowerCase() + 'offer.html';
window.location = siteHTML;
}
});

相关内容

最新更新