我試圖用多個提交按鈕進行測驗。我想要一個圖片出現十個按鈕。每次測試者按下按鈕時,我都希望發佈該值並更改圖片。到目前爲止,我已經嘗試了三種方法: - 使用onclick和javascript我可以完成所有的動畫,但是數值沒有被公佈。從谷歌我得到的印象我不得不使用更多的JavaScript來提交的價值?青少年學生的多選題圖片測驗
2.在php中使用變量時,第一張圖片會顯示並顯示第一個值,但隨後什麼也沒有發生,添加一個循環意味着所有圖片都顯示在另一個上面,而不必等待任何按鈕被點擊。
3.我試圖爲每張圖片做單獨的html頁面,然後將值發佈到php文件中,該文件的值爲$ score ++;並轉到下一個html文件,但那麼$分數是不正確的。因爲它是一個局部變量?這是否意味着我不得不在MySQL中保留價值以獲取它?此外,這似乎是一個非常浪費的方式來編程整個事情...
這裏是代碼沒有。 2:
<?php
include 'header.php';
if ($round==1) {$ans='Banana';}
if ($round==2) {$ans='Book';}
if ($round==3) {$ans='Pencil';}
...and so on
if ($_POST['submit']==$ans) {$score++; echo "Right!"; $round++; }
else
{$round++;}
?>
<html>
<form action="index.php" method="post">
<input type="submit" class="button1" name="submit" value="Banana">
<input type="submit" class="button2" name="submit" value="Balloon">
<input type="submit" class="button3" name="submit" value="Dog">
<input type="submit" class="button4" name="submit" value="Mouse">
<input type="submit" class="button5" name="submit" value="Chair">
<input type="submit" class="button6" name="submit" value="Twelve">
<input type="submit" class="button7" name="submit" value="Pen">
<input type="submit" class="button8" name="submit" value="Book">
<input type="submit" class="button9" name="submit" value="Ball">
<input type="submit" class="button10" name="submit" value="Elephant">
</form>
</html>
<?php
if($ans=="Banana")
{
echo '<img src="Banana.png" id="picture" class="picture" height="600" width="600" alt="script.aculo.us" />';
}
if($ans=="Pencil")
{
echo '<img src="Pencil.png" id="picture" class="picture" height="600" width="600" alt="script.aculo.us" />';
}
{
echo '<img src="Book.png" id="picture" class="picture" height="500" width="500" alt="script.aculo.us" />';
}
...and so on
include 'footer.php';
?>
任何幫助,將不勝感激:)
你能顯示第一個選項代碼嗎? – 2012-04-26 11:03:24
您是否嘗試過使用'a'標籤代替輸入按鈕? – karthik 2012-04-26 11:09:13