我只想在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