-1
<SCRIPT>
$(document).ready(function(){
$(document).each(function(){
var tc = document.getElementsByClassName('tc')[0].value;
var ac = document.getElementsByClassName('ac')[0].value;
  $('.ac').change(function(){
    if ($('.ac').val() > $('.tc').val()){
    alert("  ERROR !!! \n\n The attended classes are more than total classes");}
  });
});
});

$(document).ready(function(){
$(document).each(function(){
var re = new RegExp("[0-9]");
  $('.tc').change(function(){
  if ($('.tc').val().match(re)) { // DO NOTHING} 
  else {
    alert(" Please enter only numbers ");
  }
   });
});
});
</script>

上記の関数は、値が正しく、次の値が数値ではない場合、一度は機能するか、まったく機能しない可能性があります。

<table width="928" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th width="126">MONTH</th>
    <th colspan="2"><div align="center">Dec</div></th>
    <th colspan="2"><div align="center">Jan</div></th>
    <th colspan="2"><div align="center">Feb</div></th>
    <th colspan="2"><div align="center">Mar</div></th>
    <th colspan="2"><div align="center">Apr</div></th>
    <th colspan="2"><div align="center">May</div></th>
    <th colspan="2"><div align="center">Jun</div></th>
    <th colspan="3"><div align="center">I A</div></th>
    </tr>
  <tr>
    <th><div align="center">DETAILS</div></th>
    <th width="43"><div align="center">TC</div></th>
    <th width="43"><div align="center">AC</div></th>
    <th width="43"><div align="center">TC</div></th>
    <th width="43"><div align="center">AC</div></th>
    <th width="43"><div align="center">TC</div></th>
    <th width="43"><div align="center">AC</div></th>
    <th width="43"><div align="center">TC</div></th>
    <th width="43"><div align="center">AC</div></th>
    <th width="43"><div align="center">TC</div></th>
    <th width="43"><div align="center">AC</div></th>
    <th width="43"><div align="center">TC</div></th>
    <th width="43"><div align="center">AC</div></th>
    <th width="43"><div align="center">TC</div></th>
    <th width="43"><div align="center">AC</div></th>
    <th width="64"><div align="center">T1</div></th>
    <th width="64"><div align="center">T2</div></th>
    <th width="72"><div align="center">T3</div></th>
    </tr>
  <tr>
    <th>Subject-1</th>
    <td><input name="dec_tc_s1" type="text" class="tc"  value="" size="3" /></td>
    <td><input type="text" name="dec_ac_s1" class="ac" value="" size="3" /></td>
    <td><input type="text" name="jan_tc_s1" class="tc" value="" size="3" /></td>
    <td><input type="text" name="jan_ac_s1" class="ac" value="" size="3" /></td>
    <td><input type="text" name="feb_tc_s1" class="tc" value="" size="3" /></td>
    <td><input type="text" name="feb_ac_s1" class="ac" value="" size="3" /></td>
    <td><input type="text" name="mar_tc_s1" class="tc" value="" size="3" /></td>
    <td><input type="text" name="mar_ac_s1" class="ac" value="" size="3" /></td>
    <td><input type="text" name="apr_tc_s1" class="tc" value="" size="3" /></td>
    <td><input type="text" name="apr_ac_s1" class="ac" value="" size="3" /></td>
    <td><input type="text" name="may_tc_s1" class="tc" value="" size="3" /></td>
    <td><input type="text" name="may_ac_s1" class="ac" value="" size="3" /></td>
    <td><input type="text" name="jun_tc_s1" class="tc" value="" size="3" /></td>
    <td><input type="text" name="jun_ac_s1" class="ac" value="" size="3" /></td>
    <td><input type="text" name="s1_t1"   value="" size="5" /></td>
    <td><input type="text" name="s1_t2"   value="" size="5" /></td>
    <td><input type="text" name="s1_t3"   value="" size="5" /></td>
    </tr>
  <tr>
    <th>Subject-2 </th>
    <td><input type="text" name="dec_tc_s2" class="tc" value="" size="3" /></td>
    <td><input type="text" name="dec_ac_s2" class="ac"  value="" size="3" /></td>
    <td><input type="text" name="jan_tc_s2" class="tc" value="" size="3" /></td>
    <td><input type="text" name="jan_ac_s2" class="ac" value="" size="3" /></td>
    <td><input type="text" name="feb_tc_s2" class="tc" value="" size="3" /></td>
    <td><input type="text" name="feb_ac_s2" class="ac" value="" size="3" /></td>
    <td><input type="text" name="mar_tc_s2" class="tc" value="" size="3" /></td>
    <td><input type="text" name="mar_ac_s2" class="ac" value="" size="3" /></td>
    <td><input type="text" name="apr_tc_s2" class="tc" value="" size="3" /></td>
    <td><input type="text" name="apr_ac_s2" class="ac" value="" size="3" /></td>
    <td><input type="text" name="may_tc_s2" class="tc" value="" size="3" /></td>
    <td><input type="text" name="may_ac_s2" class="ac" value="" size="3" /></td>
    <td><input type="text" name="jun_tc_s2" class="tc" value="" size="3" /></td>
    <td><input type="text" name="jun_ac_s2" class="ac" value="" size="3" /></td>
    <td><input type="text" name="s2_t1" value="" size="5" /></td>
    <td><input type="text" name="s2_t2" value="" size="5" /></td>
    <td><input type="text" name="s2_t3" value="" size="5" /></td>
    </tr>
  <tr>
    <th>Subject-3 </th>
    <td><input type="text" name="dec_tc_s3" class="tc"value="" size="3" /></td>
    <td><input type="text" name="dec_ac_s3" class="ac"value="" size="3" /></td>
    <td><input type="text" name="jan_tc_s3" class="tc"value="" size="3" /></td>
    <td><input type="text" name="jan_ac_s3" class="ac" value="" size="3" /></td>
    <td><input type="text" name="feb_tc_s3" class="tc"value="" size="3" /></td>
    <td><input type="text" name="feb_ac_s3" class="ac" value="" size="3" /></td>
    <td><input type="text" name="mar_tc_s3" class="tc"value="" size="3" /></td>
    <td><input type="text" name="mar_ac_s3" class="ac" value="" size="3" /></td>
    <td><input type="text" name="apr_tc_s3" class="tc" value="" size="3" /></td>
    <td><input type="text" name="apr_ac_s3" class="ac" value="" size="3" /></td>
    <td><input type="text" name="may_tc_s3" class="tc"value="" size="3" /></td>
    <td><input type="text" name="may_ac_s3" class="ac" value="" size="3" /></td>
    <td><input type="text" name="jun_tc_s3" class="tc" value="" size="3" /></td>
    <td><input type="text" name="jun_ac_s3" class="ac" value="" size="3" /></td>
    <td><input type="text" name="s3_t1" value="" size="5" /></td>
    <td><input type="text" name="s3_t2" value="" size="5" /></td>
    <td><input type="text" name="s3_t3" value="" size="5" /></td>
    </tr>
  <tr>
    <th>Subject-4 </th>
    <td><input type="text" name="dec_tc_s4" value="" size="3" /></td>
    <td><input type="text" name="dec_ac_s4" value="" size="3" /></td>
    <td><input type="text" name="jan_tc_s4" value="" size="3" /></td>
    <td><input type="text" name="jan_ac_s4" value="" size="3" /></td>
    <td><input type="text" name="feb_tc_s4" value="" size="3" /></td>
    <td><input type="text" name="feb_ac_s4" value="" size="3" /></td>
    <td><input type="text" name="mar_tc_s4" value="" size="3" /></td>
    <td><input type="text" name="mar_ac_s4" value="" size="3" /></td>
    <td><input type="text" name="apr_tc_s4" value="" size="3" /></td>
    <td><input type="text" name="apr_ac_s4" value="" size="3" /></td>
    <td><input type="text" name="may_tc_s4" value="" size="3" /></td>
    <td><input type="text" name="may_ac_s4" value="" size="3" /></td>

    <td><input type="text" name="jun_tc_s4" value="" size="3" /></td>
    <td><input type="text" name="jun_ac_s4" value="" size="3" /></td>
    <td><input type="text" name="s4_t1" value="" size="5" /></td>
    <td><input type="text" name="s4_t2" value="" size="5" /></td>
    <td><input type="text" name="s4_t3" value="" size="5" /></td>
    </tr>
  <tr>
    <th colspan="15"><div align="center">Practicals</div></th>
    <th><div align="center">T1</div></th>
    <th><div align="center">T2</div></th>
    <th><div align="center">REC</div></th>
    </tr>
  <tr>
    <th>Subject-5 </th>
    <td><input type="text" name="dec_tc_s5" value="" size="3" /></td>
    <td><input type="text" name="dec_ac_s5" value="" size="3" /></td>
    <td><input type="text" name="jan_tc_s5" value="" size="3" /></td>
    <td><input type="text" name="jan_ac_s5" value="" size="3" /></td>
    <td><input type="text" name="feb_tc_s5" value="" size="3" /></td>
    <td><input type="text" name="feb_ac_s5" value="" size="3" /></td>
    <td><input type="text" name="mar_tc_s5" value="" size="3" /></td>
    <td><input type="text" name="mar_ac_s5" value="" size="3" /></td>
    <td><input type="text" name="apr_tc_s5" value="" size="3" /></td>
    <td><input type="text" name="apr_ac_s5" value="" size="3" /></td>
    <td><input type="text" name="may_tc_s5" value="" size="3" /></td>
    <td><input type="text" name="may_ac_s5" value="" size="3" /></td>
    <td><input type="text" name="jun_tc_s5" value="" size="3" /></td>
    <td><input type="text" name="jun_ac_s5" value="" size="3" /></td>
    <td><input type="text" name="s5_t1" value="" size="5" /></td>
    <td><input type="text" name="s5_t2" value="" size="5" /></td>
    <td><input name="s5_t3" type="text" value="" size="5" /></td>
    </tr>
  <tr>
    <th>Subject-6 </th>
    <td><input type="text" name="dec_tc_s6" value="" size="3" /></td>
    <td><input type="text" name="dec_ac_s6" value="" size="3" /></td>
    <td><input type="text" name="jan_tc_s6" value="" size="3" /></td>
    <td><input type="text" name="jan_ac_s6" value="" size="3" /></td>
    <td><input type="text" name="feb_tc_s6" value="" size="3" /></td>
    <td><input type="text" name="feb_ac_s6" value="" size="3" /></td>
    <td><input type="text" name="mar_tc_s6" value="" size="3" /></td>
    <td><input type="text" name="mar_ac_s6" value="" size="3" /></td>
    <td><input type="text" name="apr_tc_s6" value="" size="3" /></td>
    <td><input type="text" name="apr_ac_s6" value="" size="3" /></td>
    <td><input type="text" name="may_tc_s6" value="" size="3" /></td>
    <td><input type="text" name="may_ac_s6" value="" size="3" /></td>
    <td><input type="text" name="jun_tc_s6" value="" size="3" /></td>
    <td><input type="text" name="jun_ac_s6" value="" size="3" /></td>
    <td><input type="text" name="s6_t1" value="" size="5" /></td>
    <td><input type="text" name="s6_t2" value="" size="5" /></td>
    <td><input name="s6_t3" type="text" value="" size="5" /></td>
    </tr>
  <tr>
    <td colspan="18"><div align="center">
      <input type="submit"  class="button" value="Update record" onClick="t1()" />
    </div></td>
    </tr>
</table>
  <input type="hidden" name="idatten" value="" />
  <input type="hidden" name="user_att_id" value="" />
  <input type="hidden" name="MM_update" value="form1" />
  <input type="hidden" name="username" value="" />
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
<SCRIPT LANGUAGE="JavaScript">
$('.percentage').each(function() {
    if(parseInt($(this).html())>100){
    $(this).css('background', '#FFCF87' )
    alert('You Have Entered Attented class more than Total classes');
    }
    else if (parseInt($(this).html())<75){
    $(this).css('background', '#FF9B82');
    }
 });
 $('.iatotal').each(function() {
    if(parseInt($(this).html())>25){
    $(this).css('background', '#FFCF87' )
    alert('You Have Worng number Please check your entry');
    }
    else if (parseInt($(this).html())<10){
    $(this).css('background', '#FF9B82');
    }
 });
 </script>
</html>
4

1 に答える 1

2

シナリオ内の複数の要素をループするには、次のようなことを試してください。

<SCRIPT>
$(document).ready(function(){

  $('.ac').change(function(){
    $('.ac').each(function(index){
      if($('.tc').get(index)) {
        if($('.ac').get(index).val() > $('.tc').get(index).val()) {
          alert("  ERROR !!! \n\n The attended classes are more than total classes");
        }
      }
    });
  });

  var re = new RegExp("[0-9]");
  $('.tc').change(function(){
    if ($(this).val().match(re)) { 
      // DO NOTHING
    } 
    else {
      alert(" Please enter only numbers ");
    }
  });    
});    
</script>
于 2013-09-19T20:07:41.813 に答える