亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

調用 e.preventDefault() 后提交復選框表單

調用 e.preventDefault() 后提交復選框表單

PHP
慕的地8271018 2022-01-02 16:12:27
我只是似乎沒有做對,我已經嘗試了所有方法,但我無法在確認后提交表單它基本上是一個測驗系統,在提交之前輸出答案是否正確,它顯示了響應但是當我點擊確定時,它沒有提交表單來帶我去另一個問題<form id="form" method="post" action="javascript:void(0)">     <ul class="choices">      <?php while($row=$choices->fetch_assoc()): ?>      <li><input name="choice" type="radio" value="<?php echo $row['id']; ?>"/>        <?php echo $row['choice']; ?>    </li>      <?php endwhile; ?>     <input type="submit" id="submit" name="submit1" value="G?nder"/>    <input type="hidden" name="number" value="<?php echo $number; ?>"/></form>和 Bootbox.js 代碼<script src="../../css/bootbox.min.js"></script><script src="../../css/bootbox.locales.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script><script src="https://cdn.jsdelivr.net/bootbox/4.4.0/bootbox.min.js"></script><script src="https://cdn.jsdelivr.net/bootbox/4.4.0/bootbox.min.js"></script><script><?php $lesson = (int) $_GET['l'];  $number = (int) $_GET['n']; $q = "select * from `choices_tr` where question_number = $number and is_correct=1 and lesson_number=$lesson";    $result = $mysqli->query($q) or die($mysqli->error.__LINE__);    $row = $result->fetch_assoc();    $correct_choice=$row['id'];    $ChoiceFull=$row['choice'];?>$('form').on('click', "input[type='submit']", function(e){            var radioValue = $("input[name='choice']:checked").val();               if(radioValue){        if(radioValue==<?php echo $correct_choice;?> ){            e.preventDefault();            var currentTarget = event.target;  bootbox.alert({      closeButton: false,          message: '<center><i class="fa fa-check" style="font-size:48px;color:green"></i></center>',        }},});
查看完整描述

1 回答

?
一只名叫tom的貓

TA貢獻1906條經驗 獲得超3個贊

首先做這個復制這個腳本


<script>

<?php

 $lesson = (int) $_GET['l']; 

 $number = (int) $_GET['n'];

 $q = "select * from `choices_tr` where question_number = $number and is_correct=1 and lesson_number=$lesson";

    $result = $mysqli->query($q) or die($mysqli->error.__LINE__);

    $row = $result->fetch_assoc();

    $correct_choice=$row['id'];

    $ChoiceFull=$row['choice'];

?>


$('form').on('click', "input[type='submit']", function(e){

            var radioValue = $("input[name='choice']:checked").val();  

            var number = $("input[name='number']"); 

            var lesson = <?=$lesson; ?>

            if(radioValue){

        if(radioValue==<?php echo $correct_choice;?> ){

            e.preventDefault();

            var currentTarget = event.target;

  bootbox.alert({

      closeButton: false,

          message: '<center><i class="fa fa-check" style="font-size:48px;color:green"></i></center>',


    callback: function (result) {

    if (result === null) {

        } else {

           $.ajax({ 

            url: "process3.php?l=<?php echo $lesson; ?>",

            type: "post", 

            data: 'choice='+radioValue+'&number='+number+'&lesson='+lesson, 

            success: function(data){ alert('success'); } }); 

        }


},


});

setTimeout(function(){

    box.modal('hide');

}, 3000);   

                    }



else {


   e.preventDefault();

  bootbox.alert({

    closeButton: false,

         message: '<center><i class="fa fa-times" style="font-size:48px;color:red"></i></center><br /> Maalesef yanl??. Do?ru cevap: <?php echo $ChoiceFull; ?> <br /> <?php echo $questionac['explanation'] ?>',

    callback: function (result) {


    }

});


                }

            }



               });


</script>

那么現在時間是你的 php


if($_POST){


    $number = $_POST['number'];

    $selected_choice = $_POST['choice'];

    $next=$number+1;

    // you didn't send any get request remove this

    //$lesson = (int) $_GET['l']; 

    $lesson = $_POST['lesson'];

     // I found mistake till here and other code it depends on your code


    //Get total number of questions

    $query = "select * from questions_tr where lesson_number = $lesson";

    $results = $mysqli->query($query) or die($mysqli->error.__LINE__);

    $total=$results->num_rows;


    //Get correct choice

    $q = "select * from `choices_tr` where question_number = $number and is_correct=1 and lesson_number=$lesson";

    $result = $mysqli->query($q) or die($mysqli->error.__LINE__);

    $row = $result->fetch_assoc();

    $correct_choice=$row['id'];

    $ChoiceFull=$row['choice'];


    $fullquestionq = "select * from `questions_tr` where question_number = $number and lesson_number=$lesson";

    $resultful = $mysqli->query($fullquestionq) or die($mysqli->error.__LINE__);

    $resultrow = $resultful->fetch_assoc();

    $QuestionFull=$resultrow['question'];



    //compare answer with result

    if($correct_choice == $selected_choice){

        $_SESSION['score']++;

    }else{

        $_SESSION['question'][$next-1] = $QuestionFull;

        $_SESSION['answer'][$next-1] = $ChoiceFull;

    }



    if($number == $total){

        header("Location: final3.php");

        exit();

    } else {

            header("Location: Bolum3.php?n=".$next."&l=$lesson&score=".$_SESSION['score']);

    }



查看完整回答
反對 回復 2022-01-02
  • 1 回答
  • 0 關注
  • 179 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號