简体   繁体   English

Javascript根据单选按钮值单击提交按钮时重定向用户

[英]Javascript redirect user when submit button is clicked based on radio button value

What am trying to accomplish is to redirect user to a new url based on Checkbox value.我试图完成的是根据复选框值将用户重定向到一个新的 url。

Note that I am using unbounce so cannot add url to the radio button it self so am looking for a way to accomplish this with just Javascript/jQuery.请注意,我正在使用 unbounce,因此无法自行将 url 添加到单选按钮,因此我正在寻找一种仅使用 Javascript/jQuery 即可完成此操作的方法。

Scenario:设想:

User select radio button > click on submit button and new window will open with url based on radio button checked.用户选择单选按钮 > 点击提交按钮,新窗口将打开,并根据选中的单选按钮打开 url。

Hoping to see some examples with explanations here.希望在这里看到一些带有解释的例子。

Update更新

Here is my script.这是我的脚本。

$("#buttonID").on('click', function(){
switch ($("input[name=radioName]:checked")){
    case "ValOne":
        window.open("https://example.com?string1");
        break;
    case "valTwo":
        window.open("https://example.com?string2");
        break;
    case "ValThree":
        window.open("https://example.com?string3");
        break;
    case "valFour":
        window.open("https://example.com?string4");
        break;
    default: 
        break;
}
});

You can just take the value of the radio button and depending on which value you open a new window with the corresponding url:您可以只获取单选按钮的值,并根据哪个值使用相应的 url 打开一个新窗口:

$("#button").on('click', function(){
    switch ($("input[name=radioname]:checked")){
        case "radio_value_a":
            window.open("http://google.com");
            break;
        case "radio_value_b":
            window.open("http://yahoo.com");
            break;
        default:
            break;
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM