繁体   English   中英

带单选按钮的HTML页面

[英]HTML page with Radio Buttons

在您做出选择并点击“提交”后,我试图弄清楚如何让我的单选按钮将我定向到该网页。 这是我到目前为止的代码。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>

<div data-role="page">
  <div data-role="header">
  <h1>Radio Buttons</h1>
  </div>

  <div data-role="main" class="ui-content">
    <form method="post" action="demoform.asp">
      <fieldset data-role="controlgroup">
      <legend>Choose a Website:</legend>
        <label for="ESPN.com">ESPN.com</label>
        <input type="radio" name="website" id="ESPN.com" value="http://espn.go.com">
        <label for="Facebook.com">Facebook.com</label>
        <input type="radio" name="website" id="Facebook.com" value="https://www.facebook.com">
        <label for="Apple.com">Apple.com</label>
        <input type="radio" name="website" id="Apple.com" value="http://www.apple.com"> 
      </fieldset>
        <input type="submit" data-inline="true" value="Submit">
    </form>
  </div>
</div>

</body>
</html>

您应该在输入单选标记中添加事件onclick =“ document.location.href ='somepage.htm'”

您可以像这样使用JQuery:

$('input:radio[name="website"]').change(
    function(){
        if ($(this).is(':checked') && $(this).val() == '1') {
            window.location = "http://espn.go.com";
        }
        else if ($(this).is(':checked') && $(this).val() == '2'){
            window.location = "https://www.facebook.com";
        }
        else if ($(this).is(':checked') && $(this).val() == '3'){
            window.location = "http://www.apple.com";
        }
    });

HTML单选按钮

<input type="radio" name="website" id="ESPN.com" value="1">
<label for="Facebook.com">Facebook.com</label>
<input type="radio" name="website" id="Facebook.com" value="2">
<label for="Apple.com">Apple.com</label>
<input type="radio" name="website" id="Apple.com" value="3"> 
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function whichsite(form){
    var sites = form.elements.site, i = sites.length;
    while (--i > -1){
        if(sites[i].checked){
            return sites[i].value;
        }
    }
}
</script>
</head>
<body>
<form action="#" onsubmit="window.open(whichsite(this), '_blank'); return false;">
<b>Where do you need to go?:</b>
<p>
<label><input type="radio" name="site" value="http://yahoo.com/">Yahoo</label>
<label><input type="radio" name="site" value="http://google.com/">Google</label>
<label><input type="radio" name="site" value="http://amazon.com/">Amazon</label>
<label><input type="radio" name="site" value="http://cnn.com/" checked>CNN</label>
<p>
<input type="submit" value="Submit">
</form>
</body>
</html>

暂无
暂无

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

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