jquery判断下拉select和单选radio是否有值

发布时间:2021-04-10作者:小灵龙点击:139

   判断下拉和单选是否有值,最后发现单选是用null并不是空。

                 <form action="__URL__/insert" class="form-horizontal" method="post" onsubmit="return financesub()">
  
                             <select name="member_id" class="form-control" id="agency_id" >
                                        <option value="">--请选择--</option>
                                        {volist name='$member' id='vo'}
                                        <option value="{$vo.mid}" >{$vo.nickname}</option>
                                        {/volist}
                                    </select>
                             <div class="form-group">

                                   <label class="col-xs-2 control-label">充值类型*</label>

                                   <div class="col-xs-9">                                  

                                       <label class="checkbox-inline">
                                           <input type="radio" name="rech_type" value="1" > 微推圈
                                       </label>
                                       <label class="checkbox-inline">
                                           <input type="radio" name="rech_type" value="2" > 其他产品
                                       </label>
                                       <label class="checkbox-inline">
                                           <input type="radio" name="rech_type" value="3" > 赠送
                                       </label>

                                   </div>
                               </div>
        </form>

<script type="text/javascript">
        function financesub(){
            agency_id=$("#agency_id :selected").val();
             if(agency_id==''){
                 alert('代理商昵称不能为空!');
                 return false;
            }
        
            rech_type=$("input:radio[name='rech_type']:checked").val();

            if(rech_type==null){
                alert('充值类型不能为空!');
                return false;
            }         
        }       
        
    </script>

标签: