javascript - 在 Mozilla firefox 中不起作用,在 chrome 中工作正常 $ ('input[data-type="choise"]').change(function()

标签 javascript php jquery

我正在与在线测试门户合作,开发其在 chrome 中正常工作,但问题是它无法在 mozill 中正常工作。我的代码如下,它在 chrome 中工作正常,但在 mozilla firefox 中不起作用 请向我建议替代方案或解决方案。

输入[data-type="choise"]不起作用

        <script>
( document ).ready(function() {
                                $('input[data-type="choise"]').change(function() {
              var Question = $(this).attr('name');
              var Checked = $(this).attr('value');
                 y++;
              if(Checked=="0"){

              }else{
                  x++;


              }
              $('#score').replaceWith("<span id='score'><input type='hidden' name='score' id='score' value='"+ x +"' /> <input type='hidden' name='totalquestions' id='totalquestions' value='"+ y +"' /></span>");
                alert('Selected Choise for ' + Question + ' is ' + Checked+ 'and score is'+ x);

            });
            });
            </script>

        <div class="time">
        <label> Remaining Time </label> <span id="timer"></span>
        </div>
        <?php 
         include('connection.php');
        $test=$_SESSION["testnum"];
        $query=mysql_query("select * from questions where Testno='$test' order by Id ASC"); 
        if($query==true){  ?>
        <form id="scoretarget" name="formsubmit" action="congrasulations.php" method="POST">
        <span id="score"><input type="hidden" name="score" id="score" value="" />
        <input type='hidden' name='totalquestions' id='totalquestions' value="" />
        </span>
        <hr class="hr">
        <?php $id=1;
        While($row=mysql_fetch_array($query)){ ?>
            <?php 
            $questionnum=$row['Questionno'];
            $question=$row['Question'];
            $ans=$row['Answer'];
            ?>
             <div class="question">
            <div class="row">
            <div class="col-md-1">

            <label class="control-label form-inline">
            <?php echo $questionnum?>
            </label>
            </div>
            <div class="col-md-11 quest-left">
            <div class="form-group">
            <label class="control-label form-inline">
            <?php echo $question;?>
            </label>

            </div>
            <fieldset>
         <input type="radio" data-type="choise" name="q<?php echo $id; ?>" value="<?php if($ans=="Option A"){ echo"1";}else{echo"0";} ?>"><span> <?php echo $row['Option1'];?></span><br>
         <input type="radio" data-type="choise" name="q<?php echo $id; ?>" value="<?php if($ans=="Option B"){ echo"1";}else{echo"0";} ?>"><span> <?php echo $row['Option2'];?></span><br>
         <input type="radio" data-type="choise" name="q<?php echo $id; ?>" value="<?php if($ans=="Option C"){ echo"1";}else{echo"0";} ?>"><span> <?php echo $row['Option3'];?></span><br>
         <input type="radio" data-type="choise" name="q<?php echo $id; ?>" value="<?php if($ans=="Option D"){ echo"1";}else{echo"0";} ?>"><span> <?php echo $row['Option4'];?></span><br>
             </fieldset>
          </div>

          </div>
            </div><br>
          <?php ++$id;} ?>


          <input type="submit" name="proceed" value="proceed" class="btn btn-info pull-right">


          </form>

        <?php  } else{?>

        <div class="question">
            <div class="row">

        <div class="col-md-12">
        <h4 style="text-align:center; color:red;"> Question Paper is not updated  </h4>
        </div></div></div>
        <?php }

        ?>
              </div>

最佳答案

<script>
( document ).ready(function() {
                                $('input[data-type="choise"]').click(function() {
              var Question = $(this).attr('name');
              var Checked = $(this).attr('value');
                 y++;
              if(Checked=="0"){

              }else{
                  x++;


              }
              $('#score').replaceWith("<span id='score'><input type='hidden' name='score' id='score' value='"+ x +"' /> <input type='hidden' name='totalquestions' id='totalquestions' value='"+ y +"' /></span>");
                alert('Selected Choise for ' + Question + ' is ' + Checked+ 'and score is'+ x);

            });
            });
            </script>

        <div class="time">
        <label> Remaining Time </label> <span id="timer"></span>
        </div>
        <?php 
         include('connection.php');
        $test=$_SESSION["testnum"];
        $query=mysql_query("select * from questions where Testno='$test' order by Id ASC"); 
        if($query==true){  ?>
        <form id="scoretarget" name="formsubmit" action="congrasulations.php" method="POST">
        <span id="score"><input type="hidden" name="score" id="score" value="" />
        <input type='hidden' name='totalquestions' id='totalquestions' value="" />
        </span>
        <hr class="hr">
        <?php $id=1;
        While($row=mysql_fetch_array($query)){ ?>
            <?php 
            $questionnum=$row['Questionno'];
            $question=$row['Question'];
            $ans=$row['Answer'];
            ?>
             <div class="question">
            <div class="row">
            <div class="col-md-1">

            <label class="control-label form-inline">
            <?php echo $questionnum?>
            </label>
            </div>
            <div class="col-md-11 quest-left">
            <div class="form-group">
            <label class="control-label form-inline">
            <?php echo $question;?>
            </label>

            </div>
            <fieldset>
         <input type="radio" data-type="choise" name="q<?php echo $id; ?>" value="<?php if($ans=="Option A"){ echo"1";}else{echo"0";} ?>"><span> <?php echo $row['Option1'];?></span><br>
         <input type="radio" data-type="choise" name="q<?php echo $id; ?>" value="<?php if($ans=="Option B"){ echo"1";}else{echo"0";} ?>"><span> <?php echo $row['Option2'];?></span><br>
         <input type="radio" data-type="choise" name="q<?php echo $id; ?>" value="<?php if($ans=="Option C"){ echo"1";}else{echo"0";} ?>"><span> <?php echo $row['Option3'];?></span><br>
         <input type="radio" data-type="choise" name="q<?php echo $id; ?>" value="<?php if($ans=="Option D"){ echo"1";}else{echo"0";} ?>"><span> <?php echo $row['Option4'];?></span><br>
             </fieldset>
          </div>

          </div>
            </div><br>
          <?php ++$id;} ?>


          <input type="submit" name="proceed" value="proceed" class="btn btn-info pull-right">


          </form>

        <?php  } else{?>

        <div class="question">
            <div class="row">

        <div class="col-md-12">
        <h4 style="text-align:center; color:red;"> Question Paper is not updated  </h4>
        </div></div></div>
        <?php }

        ?>
              </div>

关于javascript - 在 Mozilla firefox 中不起作用,在 chrome 中工作正常 $ ('input[data-type="choise"]').change(function(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40056689/

相关文章:

javascript - 控制台.log();如何调试javascript

Javascript:如何创建 CSS3 动画

jquery - 使用 jQuery .each 和 $(this) 删除 XML 节点

javascript - 使用 jQuery UI 从选择选项中获取值

php 创建文本文件。换行符是错误的

javascript - Ember : Send child component's action to a parent component

php - Codeigniter/CSS PDF 打印输出对齐 PDF 位置

php - Doctrine\ORM\Mapping\MappingException 实体上列 'username' 的重复定义

javascript - 如何将 python/Django 列表/字典转换为 javascript

javascript - 创建一个异步的管道函数,以便可以等待函数