Javascript - 遍历表行并编辑单元格样式

时间:2015-11-05 21:42:02

标签: javascript html twitter-bootstrap loops iteration

知道为什么以下代码不起作用?我的目标是遍历每一行并根据值将样式应用于单元格。出于某种原因,我的代码只更新了第一行。

      Please choose the services you require<br><br>

              <form method="post" action="includes/guestorder.php" name="GuestForm" id="GuestForm" autocomplete="off" onsubmit="return validate();">

     <input name="services[]" type="checkbox" value="electrician"> Electrician<br>

      <input name="services[]" type="checkbox" value="health"> Health Technician<br>


      <input name="services[]" type="checkbox" value="ac"> Air Conditioning Technician<br>

            <input name="services[]" type="checkbox" value="computer"> Computer Technician<br>


      <input name="services[]" type="checkbox" value="satelite"> Satelite Service Technician<br>


      <input name="services[]" type="checkbox" value="blacksmith"> Blacksmith<br>


            <input name="services[]" type="checkbox" value="aliminium"> Aliminium Technician<br>

      <input name="services[]" type="checkbox" value="carpenter"> Carpenter<br>


            <input name="services[]" type="checkbox" value="housedecor"> Interior Designer & House Decorations<br>

                        <input name="services[]" type="checkbox" value="gardener"> Gardener<br>


                     <input name="services[]" type="checkbox" value="ceramics"> Ceramics<br>


                     <input name="services[]" type="checkbox" value="painter"> Painter<br>

                                          <input name="services[]" type="checkbox" value="nurse"> Nurse<br>

                       <input name="services[]" type="checkbox" value="delivery"> Delivery Service<br>

                         <input name="services[]" type="checkbox" value="helpers"> House Helpers (By hours)<br>

                                          <input name="services[]" type="checkbox" value="movedecor"> House Furniture Transportation<br>

                                                          <input name="services[]" type="checkbox" value="phones"> Phone Technician<br>

                                         <input name="services[]" type="checkbox" value="valet"> Valet<br>

                     <input name="services[]" id="services[]" type="checkbox" value="carw"> Car Wash<br>

         <?php



         echo "<br><fieldset>";
         echo "<legend>Your Details & Information</legend>";
         echo "Area:*<br /> <input name='area' id='area' type='text' required /><br />";
         echo "Block:*<br /> <input name='block' id='block' type='text' required /><br />";
         echo "Street Address:*<br /> <input name='streetaddress' id='streetaddress' type='text' required /><br />";
         echo "Avenue:<br /> <input name='avenue' id='avenue' type='text'><br />";
         echo "Building/House:*<br /> <input name='building' id='building' type='text' required /><br />";
         echo "Floor:<br /> <input name='floor' id='floor' type='text'><br />";
         echo "Apartment:<br /> <input name='apartment' id='apartment' type='text'><br />";
                  ?>
         What time do you need this service delivered?*<br> <input name="time" type="text" required><br>
         <?php
         echo "Phone Number:*<br /> <input name='phone' id='phone' type='text' pattern='[0-9]{8}' required /><br />"; 

                  echo "</fieldset>";
         ?>
         <br>


<input type="checkbox" name="checkbox" value="checkbox" id="checkbox" required />&nbsp;&nbsp;By checking this box, i have agreed to the <a href="/terms.php" style="color: #FFFFFF">Terms & Conditions</a>

<br>
<br>


         <input type="submit" class="submit" id="submit" value="Submit"><input type="reset" value="Reset"><br>
</form>

 <script>
     function validate(){

               if(!(document.GuestForm.services[].checked) )
     {
        alert( "Please choose a service" );
        return false;
     }
          if( document.GuestForm.area.value == "" )
     {
        alert( "Please provide your area" );
        return false;
     }

                    if(document.GuestForm.block.value == "")
     {
        alert( "Please provide your block number" );
        return false;
     }

          if( document.GuestForm.streetaddress.value == "" )
     {
        alert( "Please provide your street address" );
        return false;
     }  

                    if( document.GuestForm.building.value == "" )
     {
        alert( "Please provide your building/house number" );
        return false;
     }

                         if( document.GuestForm.time.value == "" )
     {
        alert( "Please provide the time you want the service" );
        return false;
     }

     if(document.GuestForm.phone.value == "")
     {
        alert( "Please provide your phone number" );
                return false;
     }

     if(! (document.GuestForm.checkbox.checked))
     {
        alert( "Please agree to the terms & conditions" );

        return false;
     }

     return true;
  }
  </script>

1 个答案:

答案 0 :(得分:0)

工作似乎很适合这份工作。

function blah(){

        var table = document.getElementById("tbl-appointment-requests");

        for (var i = 0, row; row = table.rows[i]; i++) {

            for (var j = 0, col; col = row.cells[j]; j++) {

                if (col.id === "alternativeAptTime") {
                    if (col.id.innerHTML === "0") {
                        col.className = "glyphicon glyphicon-remove";
                        col.innerHTML = null;
                    } else {
                        col.className = "glyphicon glyphicon-ok";
                        col.innerHTML = null;
                    }
                }

} }