-3

我在网络浏览器中输出一个测验问题。我想选择答案并单击“下一步”按钮以移至应显示在同一页面中的下一个问题。我使用 javascript 在同一页面上打印所有问题。但是,当我单击下一步时,下一个问题会打印在上一个问题的下方。

有没有一种方法可以清除页面,以便第二个问题是页面上唯一显示的问题?

我正在使用标签指向下一个问题。例如,

**在页面测试.php** * ****

<form id="q1_id" action="testcalc.php" method="post">
<fieldset>
<legend>
<?php
echo $question;
?>
</legend>
<input type="radio" name="definition1" value="<?php echo $answer1; ?>"><?php echo $answer1; ?><br>
<input type="radio" name="definition1" value="<?php echo $answer2; ?>"><?php echo $answer2; ?><br>
<input type="radio" name="definition1" value="<?php echo $answer3; ?>"><?php echo $answer3; ?><br>
</fieldset>
<button id="b1_id">Next</button>
</form>

执行此页面后,我希望能够仅打印 URL“test.php”中“testcalc.php”中存在的下一个问题。我可以使用 javascript 来做到这一点,但是这两个问题都显示在 url“test.php”下。

4

2 回答 2

0

Well, I suppose you can change your action value from action="testcalc.php" to something like action="testcalc.php?part=2" now, the first time you submit or click the button, the page will be the same, but still will add a query string of part=2 now, this will help you to manipulate the page more, as you can use the $_GET method to check if you should execute the second part of the question like:

if(!$_GET['part'] && empty($_GET['part'])) {

// show **1st part** of the questions

}else if(isset($_GET['part']) && $_GET['part']==2){

// show **2nd part** of the questions
}

Now - First time you open the page, or if you did not click any button, the 1st script will run, if you press the button however, the second part will run

于 2013-04-17T19:30:51.927 回答
0

完成这种事情的通常方法是使用 post/get 发送值到带有下一个问题的页面并使用它们创建隐藏的输入标签,并且下次将这些隐藏的输入标签也传递到下一页,或者你可以按照西蒙说的去做。

如果您希望人们能够在问题之间迁移,这将更有效率。

您添加将每个问题放在不同的页面上并将此代码添加到每个问题:

foreach($_POST as $key => $value) {
// set some validation for the type for keys you want
echo "<input type=\"hidden\" id=\"{$key}\" value=\"{$value}\" />\n";
}

唯一要做的另一件事是使用一些 javascript 设置表单的操作(以决定下一页)。这样,用户可以迁移到所有问题,而不仅仅是下一个问题。

于 2013-07-09T04:10:21.317 回答