Bootstrap multiselect onfocus无法正常工作

时间:2018-02-01 21:03:14

标签: javascript jquery html css twitter-bootstrap

当我专注于bootstrap multiselect时,我试图改变图标颜色。但onfocus不适用于多选。这是HTML代码:

<div class="col-sm-7" id="hearDiv">
 <div class="form-group">
  <div class="input-group">
   <span class="input-group-addon"><i class="fa fa-users" id="heari"></i>
   </span>
   <select class="form-control" name="hear[]" 
    id="hear" onfocusin="icon(this.id)" onfocusout="iconout(this.id)" 
    multiple>
    <option value="Google Search">Google Search</option>
    <option value="Social Media (Facebook, Instagram etc.)">Social Media 
     (Facebook, Instagram etc.)</option>
    <option value="From a Friend">From a Friend</option>
   </select>
  </div>
 </div>
</div>

这是javascript:

function icon(id){
    document.getElementById(id+"i").style.color = ("#ff3333");
}
function iconout(id){
    document.getElementById(id+"i").style.color = ("#595959");
}

1 个答案:

答案 0 :(得分:0)

尝试这种方式:

&#13;
&#13;
function icon(id) {
  id.style.color = ("#ff3333");
}

function iconout(id) {
  id.style.color = ("#595959");
}
&#13;
<div class="col-sm-7" id="hearDiv">
  <div class="form-group">
    <div class="input-group">
      <span class="input-group-addon"><i class="fa fa-users" id="heari"></i></span>
      <select class="form-control" name="hear[]" id="hear" onfocus="icon(this)" onfocusout="iconout(this)" multiple>
    <option value="Google Search">Google Search</option>
    <option value="Social Media (Facebook, Instagram etc.)">Social Media 
     (Facebook, Instagram etc.)</option>
    <option value="From a Friend">From a Friend</option>
   </select>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;