当我专注于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");
}
答案 0 :(得分:0)
尝试这种方式:
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;