javascript - javascript onClick 不工作

标签 javascript php html

我真的需要一些帮助,我整晚都在处理这个问题,只是无法让我的功能正常工作我已经尝试了所有的方法,现在我必须在一个小时内上交。

<input type="button" value="Sub" onclick = "alert('The text will be show!!'); return false;"/> 
我放在那里是有效的,但是当我尝试调用我的函数时,请注意。

非常感谢任何帮助。

<!DOCTYPE html>
<html>
<style>
</style>

<head>
  <script>
    var score = 0;

    function DoTotals() {
      window.alert("sometext");
      alert('sometext');
    }

    function getScore() {
      window.alert("sometext");
      alert("sometext");
      alert('sometext');

      var inputs = document.querySelectorAll("input");

      for (int i = 0; i < inputs; i++) {

        if (inputs[i].type == "radio" && inputs[i].checked && inputs[i].value == "correct") {
          score += 1;
        } else {

          var userInputString = inputs[i].value;
          var correctAnswer = inputs[i].getAttribute('data-correct');

          if (userInputString != null && correctAnswer != null) {

            if (userInputString.toUpperCase() == correctAnswer.toUpperCase()) {
              score += 1;
            }

          }
        }
      }

      document.getElementById("score").innerHTML = "You Scored " + score;
      score = 0;
    }
  </script>
</head>

<body>
  <input type="button" value="Sub" onclick="alert('The text will be show!!'); return false;" />

  <table border="2">
    <?php //Open the file with the questions $questionFile=f open( "testFile.txt", 'r'); $radioGroupId=0; //while the reader has npt reached the end of the file while(!feof($questionFile)){ //get line for text file $line=f gets($questionFile); echo '<tr>';
    //If this line is a multiple choice question if(strpos($line, '#MC') !==f alse){ //break the line into substrings $breakDownLine=e xplode( ';',$line); //insert each element of the array into the table for ($i=0;$i<count($breakDownLine);$i++){ if($i==0){
    //Remove the MC indicator $question=s tr_replace( "#MC", "",$breakDownLine[$i]); echo '<td style="border:2px solid red;">'; echo $question. '</td>'; } else{ echo '<td style="border:2px solid black;">'; if(strpos($breakDownLine[$i], '*')!=false){ $answerRemove=s
    tr_replace( "*", "",$breakDownLine[$i]); echo $answerRemove. '<input type="radio" name="var'.$radioGroupId. '" value="correct">'; } else{ echo $breakDownLine[$i]. '<input type="radio" name="var'.$radioGroupId. '" value="incorrect">'; } } } } //If
    this line is a True / False question else if(strpos($line, '#TF') !==f alse){ //break the line into substrings $breakDownLine=e xplode( ';',$line); for ($i=0;$i<count($breakDownLine);$i++){ if($i==0){ //Remove the MC indicator $question=s tr_replace(
    "#TF", "",$breakDownLine[$i]); echo '<td style="border:2px solid red;">'; echo $question. '</td>'; } else{ echo '<td style="border:2px solid black;">'; if(strpos($breakDownLine[$i], '*')!=false){ $answerRemove=s tr_replace( "*", "",$breakDownLine[$i]);
    echo $answerRemove. '<input type="radio" name="var'.$radioGroupId. '" value="correct">'; } else{ echo $breakDownLine[$i]. '<input type="radio" name="var'.$radioGroupId. '" value="incorrect">'; } } } } else if(strpos($line, '#FIB') !==f alse){ echo
    '<td style="border:2px solid red;">'; while (true){ $pos=s trpos($line, "["); $pos2=s trpos($line, "]"); $pos3=$ pos2-$pos; $subAnswer=s ubstr($line,$pos+1,$pos3-1); if ($pos2===f alse) { echo $line; break; // no more blanks i.e. no more [. } else { $out=s ubstr($line,0,$pos); echo
    $out; $line=s ubstr($line,$pos2+1,strlen($line)); echo '<input type="text" data-correct="'.$subAnswer. '">'; } } } echo '</tr>'; $radioGroupId++; } ?>


  </table>

  <button onClick="DoTotals()">Click me</button>
  <p id="score"></p>

</body>

</html>

最佳答案

代替

for (int i = ...

写:

for (var i = ...

关于javascript - javascript onClick 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33432464/

相关文章:

javascript - Jquery Header 在悬停时添加类

html - 如何使页面顶部的栏在html中消失

javascript - 在视频元素顶部移动时,JQuery UI 可调整大小/可拖动丢失 'grip'

javascript - 仅在选择范围后才在范围 slider 观察器内执行代码,而不是在滑动 slider 时不断执行?

php - 如何从javascript获取值到php

PHP递归函数问题

html - 在一个较小的容器中溢出一个较大的容器并将其居中

javascript - Aurelia JS - Kendo UI 垂直 slider 的高度百分比?

javascript - 按值过滤 JavaScript 对象

php - 具有多个 PHP 变量和动态文本的 Mod_Rewrite