我创建了一个下拉菜单,其中有多个选项可供选择。 但是,无论我选择哪种选项,都会将我定向到相同的URL。在这种情况下,最后编写的代码。有人可以告诉我代码中我错过了什么吗?
import wixLocation from 'wix-location';
$w.onReady(function () {
$w("#dropdown1").onChange((event, $w) => {
console.log(event.target.value); //iPhone X
wixLocation.to("/iphonex");
});
});
$w.onReady(function () {
$w("#dropdown1").onChange((event, $w) => {
console.log(event.target.value); //iPhone XS
wixLocation.to("/iphonexs");
});
});
$w.onReady(function () {
$w("#dropdown1").onChange((event, $w) => {
console.log(event.target.value); //iPhone XS MAX
wixLocation.to("/iphonexsmax");
});
});
答案 0 :(得分:0)
您只需要一个事件处理程序。您需要转到值
如果有多个,则执行最后一个
...
Frm05715 in 'fontes\Frm05715.pas' {Form05715},
Frm99903 in 'fontes\Frm99903.pas' {Form99903};
{$R *.res}
begin
Application.Initialize;
...
Application.Run;
如果您改为将选项的VALUE设置为iphonex,iphonexs等,则只需
import wixLocation from 'wix-location';
$w.onReady(function () {
$w("#dropdown1").onChange((event, $w) => {
var page = event.target.value); //"iPhone X" OR "iPhone XS" etc
if (page) wixLocation.to("/"+page.replace(/\s+/g,"").toLowerCase());
});
});