如何使用按钮将单选按钮 link 添加到页面

How do i make a radio button link to a page using a button

我如何制作一个单选按钮,它可以 link 到一个页面,每个单选按钮都被 link 编辑到一个网站,当我按下一个按钮时,我想让它引导我到选定的单选按钮 link 我不希望它是 onclick 我希望它在我按下按钮时引导我。我试过这样做,但我需要帮助。 这是我试过的:

    <h3>
Which part of the building do you want cleaning
</h3>
<form name="frmSite" style="float: left; margin-top: 5px;"> 
  <a class="loginPg_choices" href="www.youtube.com">
    <input type="radio" name="site" value="1" id="radio_btn_1" style="float: left; clear: both;" />
    <span style="float: left; margin: -2px 0 0 5px;">The whole building</span>
    <br/> 
  </a>
  <a class="loginPg_choices" href="www.google.com">
    <input type="radio" name="site" value="1" id="radio_btn_1" style="float: left; clear: both;" />
    <span style="float: left; margin: -2px 0 0 5px;">Kithcen</span>
    <br/> 
  </a>
  <a href="#" type="submit" value="Submit" title="Login" style="float: right; clear: both;">
    Submit
  </a>
</form>

这是我试过的 https://jsfiddle.net/nb7jmfxp/

Here 是字段集文档。

Html代码:

<form>
  <fieldset>
    <legend>Choose your Website</legend>

    <input type="radio" id="youtube" name="monster">
    <label for="youtube">Youtube</label><br />

    <input type="radio" id="google" name="monster">
    <label for="google">Google</label><br />

  </fieldset>
</form>
<button id="go_to_website">
  Go to website
</button>

js代码:

  $("#go_to_website").click(function(event) {
    var link_id = $("input[name='monster']:checked").attr("id");
    if (link_id) {
      switch (link_id) {
        case "youtube":
          // code block
          window.location.href = 'www.youtube.com';
          break;
        case "google":
          // code block
          window.location.href = 'www.google.com';
          break;
        default:
          // code block
      }
    } else {
      alert("please pick an option")
    }
  })

Jsfiddle link: https://jsfiddle.net/pc62oL74/4/

希望对您有所帮助。