Я просто вызываю функцию highlightInput(this)
, которая просто меняет цвета для выбранного ввода.Я думаю, что может быть лучший способ избежать повторения.Есть идеи?
HTML-файл
<div class="form-group">
<label for="your_name">Your name:</label>
<input type="text" class="form-control" name="your_name" onfocus="highlightInput(this);">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" name="email"onfocus="highlightInput(this);">
</div>
<div class="form-group">
<label for="title">Event title:</label>
<input type="text" class="form-control" name="title"onfocus="highlightInput(this);">
</div>
<div class="form-group">
<label for="location">Event location:</label>
<input type="text" class="form-control" name="location"onfocus="highlightInput(this);">
</div>
Как выглядит highlightInput:
var Color = {
inputColor:function (color, self){
$(self).css('backgroundColor', color);
}
}
function highlightInput(self){
Color.inputColor('lightyellow', self);
$(self).blur(function(){
Color.inputColor('white', self);
});
}