Html 如何使用按钮创建指向页面的单选按钮链接
我如何制作一个单选按钮,它可以链接到一个页面每个单选按钮都链接到一个网站,当我按下一个按钮时,我希望它将我指向所选的单选按钮链接,我不希望它被点击,我希望它在我按下按钮时将我指向。我试过这样做,但我需要帮助。 这就是我所尝试的:Html 如何使用按钮创建指向页面的单选按钮链接,html,button,radio-button,Html,Button,Radio Button,我如何制作一个单选按钮,它可以链接到一个页面每个单选按钮都链接到一个网站,当我按下一个按钮时,我希望它将我指向所选的单选按钮链接,我不希望它被点击,我希望它在我按下按钮时将我指向。我试过这样做,但我需要帮助。 这就是我所尝试的: <h3> Which part of the building do you want cleaning </h3> <form name="frmSite" style="float: left; margin-top: 5px;
<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>
你想打扫大楼的哪一部分
这里是我尝试过的是字段集文档
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>
JSIDLE链接:
希望它能有所帮助
$("#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")
}
})