使用jquery,max age必须大于min age

时间:2016-12-15 06:42:43

标签: php

enter image description here 我的代码写在下面。年龄组年龄必须等于或小于年龄才能请求帮助

<select name="age_from" class="form-control">
    <option value="18"
        @if(old('age_from'))
            {{ old('age_from') }} 
        @else 
            18 
        @endif
    >
        @if(old('age_from'))
            {{ old('age_from') }} 
        @else 18 @endif
    </option>
        @for($i=19;$i<=65;$i++)

            <option>{{$i}}</option> 
        @endfor
</select>


<select name="age_to" class="form-control">
    @for($i=18;$i<65;$i++)
        <option>{{$i}}</option> 
    @endfor
        <option selected>
            @if(old('age_to')) 
                 {{ old('age_to') }}
            @else 
                 65+ 
            @endif
        </option>
</select>

1 个答案:

答案 0 :(得分:2)

(文档)$。就绪(函数(){      $( “AGE_TO”)。变化(函数(){

     var age_from =$('.age_from').val();
        var age_to =$('.age_to').val();
     if(age_from > age_to ){
         $('.age_to').css('border-color', 'red');
         $('.age_warrning').show();
     }else{
         $('.age_to').css('border-color', '');
         $('.age_warrning').hide();
         }
        });
 $(".age_from").change(function(){

     var age_from =$('.age_from').val();
        var age_to =$('.age_to').val();
     if(age_from > age_to ){
         $('.age_to').css('border-color', 'red');
         $('.age_warrning').show();
     }else{
         $('.age_to').css('border-color', '');
         $('.age_warrning').hide();
         }
        });
    });