Angularjs:如何编写测验托盘的选项代码?

时间:2017-09-09 16:13:36

标签: javascript html css angularjs web

在制作测验网站的过程中,我准备了一个25个问题托盘。如果我在一个问题上选择选项1并转移到另一个问题,那么其余问题似乎是选项1。我使用过选项的单选按钮,但我无法弄清楚如何准备单个问题的答案。我使用角度js和bootstrap。

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html>

<head>
  <title>quizzzzzz</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link href="css/style.css" rel="stylesheet">
  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <style type="text/css">
    body {
      background-color: khaki;
    }

    .navbar-custom {
      background-color: black;
      padding: 0px;
    }

    .navbar-custom .navbar-brand {
      font-family: Geneva;
      font-size: 30pt;
      color: white;
    }

    .toggleButton {
      width: 160px;
      height: 60px;
      line-height: 60px;
      margin: 0 auto;
      background: #D35400;
      color: #fff;
      border: 3px solid rgba(255, 255, 255, 0.5);
      text-align: center;
      cursor: pointer;
      user-select: none;
      text-transform: uppercase;
    }
  </style>

</head>

<body ng-app="mainModule">
  <nav class="navbar navbar-custom">
    <div class="container-fluid">
      <div class="navbar-header">
        <a class="navbar-brand" href="ex.html">Quiz</a>
      </div>
      <div class="collapse navbar-collapse" id="myNavbar">
        <form class="navbar-form navbar-right">
        </form>
      </div>
    </div>
  </nav>
  <div ng-hide="p1">
    <div class="input-field col s12 m6 14">
      <center>
        <i class="fa fa-search"></i>
        <input id="search" type="text" style="width:350px" ng-model='search'>
        <label for="search">Search</label>
      </center>
    </div>

    <section class="pannel-1">
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <div class="panel panel-default p1">
              <div class="panel-body">
                Please Read The Following Instruction Carefully
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
    <section class="technologies" ng-controller="techlistcon">

      <center><button class="btn btn-primary" ng-click="fun()">START</button></center>

      <div class="container">
        <div class="row">
          <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12" ng-repeat="tech in techlist|filter:search">
            <div class="box box-block bg-white tile tile-1 mb-2">
              <div class="t-content">
                <h1 class="mb-1">{{tech.name}}</h1>
                <a href="" data-toggle="modal" data-target="#login-modal" ng-click="techlist_full(tech)" class="btn btn-info pull-right">More>></a>
              </div>
            </div>
          </div>

        </div>
      </div>
      <div class="modal fade" id="login-modal">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-body">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">{{tech_full.name}}</h4>
              </div>
              <table class="table">
                <tr>
                  <td><img ng-src="{{tech_full.img}}" width="100"></td>
                  <td>{{tech_full.desc}}</td>
                </tr>
              </table>
            </div>
          </div>
        </div>
      </div>
  </div>
  <div ng-show="p1">
    <section class="pannel-1">
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <div class="panel panel-default p1">
              <div class="panel-body">
                Online Exam : You Can Test Your Skills
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
    <section class="questions" ng-controller="questionlistcon">
      <div class="container">
        <div class="row">
          <div class="col-md-7">
            <div class="q-box">
              <div class="question">
                <h4>{{currentIndex+1}}.{{currentque.question}}</h4>
              </div>
              <div class="options">
                <ul>
                  <li><input type="radio" name="{{$index+1}}" value="{{$currentIndex+1}}">{{currentque.o1}}</li>
                  <li><input type="radio" name="{{$index+1}}" value="{{$currentIndex+1}}">{{currentque.o2}}</li>
                  <li><input type="radio" name="{{$index+1}}" value="{{$currentIndex+1}}">{{currentque.o3}}</li>
                  <li><input type="radio" name="{{$index+1}}" value="{{$currentIndex+1}}">{{currentque.o4}}</li><br>
                </ul>
                <button class="btn btn-warning" ng-hide="b" ng-click="next()">Next</button>

                <button class="btn btn-warning" ng-hide="b" ng-click="prev()">prev</button>
                <button class="btn btn-warning" ng-show="b">Finish</button>
              </div>
            </div>
          </div>
          <div class="col-md-5">

            <div class="q-box">
              <h4>Question Palette</h4>
              <div id="main_right">
                <div class="questionpallat">
                  <ul>
                    <li ng-repeat="x in questions">

                      <a class="btn btn-danger buttons" ng-click="currentq($index)" style="width:35px">{{$index+1}}</a>

                    </li>
                  </ul>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>
  <section class="pannel-1">
    <div class="container">
      <div class="row">
        <div class="col-md-12">
          <div class="panel panel-default p1">
            <div class="panel-body">
              <center> Here comes your RESULT>>>>>>>>>>>>></center>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <!-- Include all compiled plugins (below), or include individual files as needed -->
  <script src="js/bootstrap.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"></script>
  <script src="js/app.js"></script>
  <script src="js/controllers/techlist.js"></script>
</body>

</html>

Javascript:

var vm=angular.module("quizApp",[]);
vm.controller("technologies",function($scope){
    $scope.technologyar=["HTML5","PHP"];
});
vm.controller("questions",function($scope){
    var index=0;
    $scope.questionar=[
    {
        question:'What does HTML stand for?',
            o1:'client side',
            o2:'serverside',
            o3:'database',
            o4:'none'
    },
    {
        question:'PHP is?',
            o1:'client side',
            o2:'serverside',
            o3:'database',
            o4:'none'
    },
    {
        question:'Java is?',
            o1:'client side',
            o2:'serverside',
            o3:'database',
            o4:'none'
    },
    {
        question:'css is?',
        o1:'client side',
        o2:'serverside',
        o3:'database',
        o4:'none'
    }
    ];

    $scope.currentque=$scope.questionar[index];
        $scope.next=function(){
            if(index<$scope.questionar.length-1){
                    index++;
        $scope.currentque=$scope.questionar[index];
        }
    }
        $scope.prev=function(){
                if(index>0){
                index--;
        $scope.currentque=$scope.questionar[index];
        }
    }
        $scope.currentq=function(code){
            index=code;
        $scope.currentque=$scope.questionar[index];

        }
    });

0 个答案:

没有答案