活动重点在于实现物化

时间:2018-09-17 17:12:56

标签: javascript jquery css materialize

我想在class具有select event时添加一个select,这是我的代码:

$("form").find("input,select").on('focus',function(){
     $(this).addClass("focus");
});
$("form").find("input,select").on('blur',function(){
     $(this).removeClass("focus");
});

这是我的HTML

            <form id="formEdit" method="post" action="<?=current_url();?>" enctype="multipart/form-data">
                  <div class="form-pad">
                     <div class="row">
                        <!--<div class="col s12 m8 push-m4">-->
                          <div class="col s12">
                          <div class="input-field">
                              <input id="nombre" name="nombre" type="text" class="validate"  onkeypress="return valid_text(event)" maxlength="20" value="<?=$nombre;?>" required>
                              <input name="userID" type="hidden" value="<?=$userID;?>">
                              <input name="status" type="hidden" value="<?=$status;?>">
                              <label for="nombre" class="active">Nombres</label>
                           </div>
                           <div class="input-field">
                              <input name="apellidos" type="text" class="validate"  onkeypress="return valid_text(event)" maxlength="30" value="<?=$apellidos;?>" required>
                              <label for="apellidos" class="active">Apellidos</label>
                           </div> 
                           <div class="input-field">
                              <input name="email" type="email" class="validate"  maxlength="49" value="<?=$correo;?>" required>
                              <label for="email" class="active">Correo Electrónico</label>
                           </div>                           
                           <div class="input-field">
                              <select id="select_privilegios" name="FK_id_rol" required>
                                 <?=($id_rol=='') ? '<option value="" disabled selected>Seleccionar</option>': ''?>
                                <?php
                                  foreach ($roles as $role) {
                                    echo '<option value="'.$role->roleId.'" '.(($id_rol == (int)$role->roleId) ? 'selected': '').'>'.$role->role.'</option>';
                                  }
                                ?>
                              </select>
                              <label>Privilegios</label>
                           </div>                    
                           <div id="div_empresas" class="input-field">
                              <select name="id_empresa[]" id="select_empresas" multiple required>
                                <?php
                                $ids = array_map(function($e) {
                                  return is_object($e) ? $e->id_empresa : $e['id_empresa'];
                                  }, $id_empresa);

                                  foreach ($empresas as $empresa) { 
                                    echo '<option value="'.$empresa->id_empresa.'" '.(in_array($empresa->id_empresa, $ids) ? 'selected': '').'>'.$empresa->nombre .'</option>';                                   
                                  }
                                ?>
                                </select>
                              <label>Empresas</label>
                           </div>                                                 


                        </div>
                     </div>
                     <!-- Save Cancelar -->
                     <div class="row">
                        <div class="col s12 m12 l12 buttons" style="padding: 0">
                            <div id="botones">
                                <button class="waves-effect waves-light btn" type="submit" name="action1"><i class="material-icons right">done</i>Guardar</button>
                                <?php if($userID>0): ?>
                                <span  href="#warningModal" class="modal-trigger waves-effect waves-light btn <?=($status)? "red lighten-1" : "blue darken-4";?>"><i class="material-icons right"><?=($status)? "delete" : "lock_open";?></i><?=($status)? "Eliminar" : "Habilitar";?></span>
                                <button type="submit" name="action2" class="hide"></button>
                                <?php endif; ?>
                                <a href="<?php echo base_url(); ?>/usuarios" id="cancelar" class="waves-effect waves-light btn blue-grey lighten-2"><i class="material-icons right">clear</i>Cancelar</a>
                            </div> 
                        </div>
                     </div>
                  </div>
               </form>

此代码在input text或其他类型的input中非常有效,但是在select元素中未检测到焦点事件。如果有人可以帮助我 我会非常感激。

0 个答案:

没有答案