gpt4 book ai didi

javascript - html表单捕获数据制作url

转载 作者:行者123 更新时间:2023-11-28 21:10:57 25 4
gpt4 key购买 nike

有人可以解释一下我如何从两个下拉字段中捕获数据,并在按下提交按钮时将这两个选择值连接在一起以创建一个随后调用的 URL。

例如。

下拉菜单 1:苹果下拉菜单 2:橙色

当您单击提交按钮时,它会创建一个 url 并加载:

http://www.fruittopick.com/apple-orange.html <-- 它连接“apple”&“-”&“orange”&“.html”,然后加载该页面。

最佳答案

您可以创建一个在提交表单时调用的 JavaScript 函数,例如见下文

function genURL()
{
var orange= document.getElementById('orangeCombo');
var apple= document.getElementById('appleCombo');
var finalURL="www.test.com"; // you can configure as per your need
finalURL= finalURL+orange+apple; // you can configure as per your need
window.location.href=finalURL; // to load generated URL
}

希望有帮助

关于javascript - html表单捕获数据制作url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8688485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com