0

我需要一些有关 javascript 重定向的帮助。我有以下表单代码,但它不起作用。

<form name="getstarted" width="500">  
    <p>

        <select name="trade" id="trade">  
          <option selected="selected" value = "">Please Select License Trade</option>  
          <option value = "A">A-General Engineering</option>  
          <option value = "B">B-General Building</option>  
          <option value = "C2">C2 - Insulation and Acoustical</option>  
        </select>  

    </p>

    <p>Do you currently hold an <strong>active</strong> contractors license in California? <br /> <br />
        <INPUT TYPE="radio" id="questions" NAME="questions" VALUE="y">Yes
        <INPUT TYPE="radio" id="questions" NAME="questions" VALUE="n">No</p>

     <input type="button" value="Next" onClick = "direction()" />  

</form>

<script language="javascript">  
function direction(value)     
{  
    if((trade == "A") && (questions == "y"))  
    {window.location = "http://localhost:8080/Math/page1.html";}  

    else{window.location = "http://localhost:8080/Math/page2.html";}  
}  
</script>
<script type="text/javascript">
        $(document).ready(function(){
            $(".icon a.tooltips").easyTooltip();
        });
</script>

我试图让此代码根据选择的两个不同选项重定向用户。
谢谢

4

1 回答 1

1

尝试这个:

function direction(value) {
    var trade = $("#trade").val();
    var questions = $(".questions:checked").val();
    if ((trade == "A") && (questions == "y")) {
        window.location = "http://localhost:8080/Math/page1.html";
    } else {
        window.location = "http://localhost:8080/Math/page2.html";
    }
}

演示在这里

我添加的内容:

var trade = $("#trade").val();
var questions = $(".questions:checked").val();

并删除了重复的 ID 并改用了一个类:

    <INPUT TYPE="radio" class="questions" NAME="questions" VALUE="y"/>Yes
    <INPUT TYPE="radio" class="questions" NAME="questions" VALUE="n"/>No
于 2013-10-15T18:29:33.527 回答