0

我必须使用javascript函数显示重定向页面,增量为1。但是当我尝试这个时,我得到了 NaN Error 。谁能帮我解决问题。我在下面附上了我的来源。像这个 quiz.php?qusId=NaN。

    <script type="text/javascript">
        function handler(var1,quizId) {
            alert(var1);
            var id = parseInt(quizId);
            window.location = "quiz.php?qusId="+parseInt(quid(id));
        }
        function quid(quzId){
            if(quzId == 1){
                return 1;
            }else{
                return quzId++;
            }
        }
    </script>
</head>
<body>
    <?php 
        $qusId=$_GET['qusId'];
        ?>
        <form action="test.php" method="POST">
            <?php
                $result = select("SELECT * FROM questions WHERE question_id='$qusId'");
                //$row = mysql_fetch_array($result);
                $i=$_GET['qusId'];
                while($row = mysql_fetch_array($result))
                {
                    ?>
                        <table width="581" height="299" border="1">
                            <tr>
                                <td>Union Assurance Questionnaire</td>
                            </tr>
                            <tr>
                                <td>
                                    <?php 
                                        echo $i.'.' .$row['questions']; 
                                        $i++;
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <?php 
                                        $qId=$row['question_id'];
                                        $result1=select("SELECT * FROM answers WHERE questionId='$qId' ORDER BY RAND()");
                                        while($row1=mysql_fetch_array($result1)){
                                            ?>
                                                <input type="radio" name="answers" value="<?php echo $row1['answers'];?>"  onclick="handler('<?php echo $row1["feedback"]; ?>,<?php echo $qusId;?>')" /><?php echo $row1['answers']; ?><br/>
                                            <?php 
                                        } 
                                    ?>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                        </table>
                    <?php
                }
            ?>
        </form>
4

1 回答 1

2

在您的点击处理程序中,您有

handler('<?php echo $row1["feedback"]; ?>,<?php echo $qusId;?>')

您将单引号放在错误的位置 - 它作为单个参数传递到您的“处理程序”函数中。请尝试:

handler('<?php echo $row1["feedback"]; ?>',<?php echo $qusId;?>)
于 2012-09-24T11:22:52.033 回答