1

好的。我不知道我在做什么。我要回去帮助人们找工作。我在 Fiddle 中运行了所有内容并将其迁移到两个不同的编辑器中,一切正常,但没有任何反应,没有警报,没有点击提交。我在我的笔记本电脑上试了一下,显示了两个页面,其中一个带有 profilebannerIE,另一个带有 html。再次感谢。

jquery 新手。我们有一个表格,我们希望人们填写并提交。创建表单并不难,但现在我们希望它做一些特殊的事情。我已经研究并尝试了 3 天不同的东西,这是我最后的努力。您的许多论坛创意都非常聪明,我相信您很快就能实现。提前致谢!

如果七个或更多单选按钮被单击“是”,我们正在尝试让以下表单上的提交按钮转到“网站 1”。如果少于 7 个“是”答案,我们希望它转到“网站 2”。

<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
 <title>Survey</title>
</head>
<body>
<h1 style="text-align: center;"><big><span
 style="font-family: Arial Unicode MS; background-color: white; color: rgb(0, 0, 153);">Survey</span></big></h1>
<div
 style="text-align: center; font-family: Arial Unicode MS; color: rgb(0, 0, 153); font-weight: bold;"><big>Please
answer the following questions and click the 'Submit' button at the bottom of the page.</big></div>
<form method="post" action="http://www.workintexas.com"
 name="Customer Survey"><br>
Are you currently employed?<br>
  <input name="Employed" value="Yes" type="radio">Yes<br>
  <input name="Employed" value="No" type="radio">No<br>
  <br>
Do you have readily available, documents to support your authorization to work in the USA?<br>
  <input name="Documents" value="Yes" type="radio">Yes<br>
  <input name="Documents" value="No" type="radio">No<br>
  <br>
Do you have a resume?<br>
  <input name="Resume" value="Yes" type="radio">Yes<br>
  <input name="Resume" value="No" type="radio">No<br>
  <br>
Do you have reliable transportation?<br>
  <input name="transportation" value="Yes" type="radio">Yes<br>
  <input name="transportation" value="No" type="radio">No<br>
  <br>
Do you have a high school diploma or equivalent?<br>
  <input name="Diploma" value="Yes" type="radio">Yes<br>
  <input name="Diploma" value="No" type="radio">No<br>
  <br> 
Do you have an occupational license, certification, or advanced level of education?<br>
  <input name="Cert" value="Yes" type="radio">Yes<br>
  <input name="Cert" value="No" type="radio">No<br>
  <br>
Have you been unemployed longer than 6 months?<br>
  <input name="Unemployed" value="Yes" type="radio">Yes<br>
  <input name="Unemployed" value="No" type="radio">No<br>
  <br>
Have you had more than three jobs within the last two years?<br>
  <input name="Jobs" value="Yes" type="radio">Yes<br>
  <input name="Jobs" value="No" type="radio">No<br>
  <br>
Do you have appropriate interview clothing?<br>
  <input name="Clothing" value="Yes" type="radio">Yes<br>
  <input name="Clothing" value="No" type="radio">No<br>
  <br>
Do you have a criminal background?<br>
  <input name="Background" value="Yes" type="radio">Yes<br>
  <input name="Background" value="No" type="radio">No<br>
  <br>
  <input name="Submit" value="Submit" type="submit"><small><br>
  <br>
  <br>
 </form>
</body>
</html>
4

2 回答 2

1

仅供将来参考,有一个名为 jsFiddle 的漂亮工具,您可以使用它为我们提供更好的代码来使用:jsFiddle

我已经为你做了一个快速的解决方案,可以让你从这里开始

var answered_yes = 0;
$("input[type=radio]:checked").each(function() {
    if ($(this).val() === "Yes") {
        answered_yes++;
    }
});
if (answered_yes >= 7) {
    location.href = "7 or more website.html";
} else {
    location.href = "less than 7 website.html";
}

完整标记

这是您可以使用的标记(使用 CDN 中包含的 jQuery 库),您的标记需要相当多的工作,但您已经明确表示您是初学者,所以我会向您扔骨头。看看你是否能得到进一步的结果。

<html>
<head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    <title>Survey</title>
</head>
<body>
    <h1 style="text-align: center;">
        <big><span style="font-family: Arial Unicode MS; background-color: white; color: rgb(0, 0, 153);">Survey</span></big>
    </h1>
    <div style="text-align: center; font-family: Arial Unicode MS; color: rgb(0, 0, 153); font-weight: bold;">
        <big>Please answer the following questions and click the 'Submit' button at the bottom of the page.</big>
    </div>
    <form method="post" action="http://www.workintexas.com" name="Customer Survey">
        <br>Are you currently employed?<br>
        <input name="Employed" value="Yes" type="radio">Yes<br>
        <input name="Employed" value="No" type="radio">No<br>
        <br>Do you have readily available, documents to support your authorization to work in the USA?<br>
        <input name="Documents" value="Yes" type="radio">Yes<br>
        <input name="Documents" value="No" type="radio">No<br>
        <br>Do you have a resume?<br>
        <input name="Resume" value="Yes" type="radio">Yes<br>
        <input name="Resume" value="No" type="radio">No<br>
        <br>Do you have reliable transportation?<br>
        <input name="transportation" value="Yes" type="radio">Yes<br>
        <input name="transportation" value="No" type="radio">No<br>
        <br>Do you have a high school diploma or equivalent?<br>
        <input name="Diploma" value="Yes" type="radio">Yes<br>
        <input name="Diploma" value="No" type="radio">No<br>
        <br>Do you have an occupational license, certification, or advanced level of education?<br>
        <input name="Cert" value="Yes" type="radio">Yes<br>
        <input name="Cert" value="No" type="radio">No<br>
        <br>Have you been unemployed longer than 6 months?<br>
        <input name="Unemployed" value="Yes" type="radio">Yes<br>
        <input name="Unemployed" value="No" type="radio">No<br>
        <br>Have you had more than three jobs within the last two years?<br>
        <input name="Jobs" value="Yes" type="radio">Yes<br>
        <input name="Jobs" value="No" type="radio">No<br>
        <br>Do you have appropriate interview clothing?<br>
        <input name="Clothing" value="Yes" type="radio">Yes<br>
        <input name="Clothing" value="No" type="radio">No<br>
        <br>Do you have a criminal background?<br>
        <input name="Background" value="Yes" type="radio">Yes<br>
        <input name="Background" value="No" type="radio">No<br>
        <br><input name="Submit" value="Submit" type="submit"><small><br>
        <br>
        <br>
    </form>
    <script type="text/javascript" href="http://code.jquery.com/jquery-1.10.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("input[type=submit]").bind("click", function (e) {
                e.preventDefault();
                var answered_yes = 0;
                $("input[type=radio]:checked").each(function () {
                    if ($(this).val() === "Yes") {
                        answered_yes++;
                    }
                });
                if (answered_yes >= 7) {
                    location.href = "7 or more website.html";
                } else {
                    location.href = "less than 7 website.html";
                }
            });
        });
    </script>
</body>
</html>
于 2013-07-02T14:30:43.277 回答
0

您可以尝试以下代码来获取选中单选按钮的计数,它的示例代码

HTML

<label><input type="radio" value="1" name="rdQueen" /> Scaramouche</label> <br />
<label><input type="radio" value="1" name="rdQueen" /> Will you do the</label> <br />
<label><input type="radio" value="1" name="rdQueen" /> Fandango</label> <br />

<label><input type="radio" value="1" name="rdFruit" /> Mango</label> <br />
<label><input type="radio" value="1" name="rdFruit" /> Kiwi</label> <br />
<label><input type="radio" value="1" name="rdFruit" /> Potato</label> <br />

<button id="test">Run test</button>

jQuery

$('#test').click(function(){
    if($(':radio[name=rdQueen]:checked, :radio[name=rdFruit]:checked').length == 2)
        alert('good to go');
    else
        alert('please choose one from each group');
});
于 2013-07-02T14:25:18.287 回答