我只想在focus.how上选择“请选择”时,才将css class dropdownliststyle添加到下拉菜单中吗?如何使用jquery添加类到dropdownlist取决于选项
,这里是我的jsfiddle链接https://jsfiddle.net/3dj3srxp/到
CSS
.DropDownStyle {
background-color: red;
color: white;
}
jQuery的
$(document).ready(function() {
$('input[type="text"]').each(function() {
$(this).focus(function() {
$(this).addClass('textBoxStyle');
});
$(this).blur(function() {
$(this).removeClass('textBoxStyle');
});
});
$('select').focus(function() {
$(this).addClass('DropDownStyle');
});
$('select').blur(function() {
$(this).removeClass('DropDownStyle');
});
});
看到我更新的答案...它会更好地使用“更改”功能,并检查值...我在我的答案更新你的小提琴。 – kevindeleon