只有再写一个blur方法才能还原吗?
$('.search input').focus(function(){
$(this).css({
'backgroundColor': '#fff'
}).closest('.search').css({
'backgroundColor': '#fff'
});
});
只有再写一个blur方法才能还原吗?
$('.search input').focus(function(){
$(this).css({
'backgroundColor': '#fff'
}).closest('.search').css({
'backgroundColor': '#fff'
});
});
13 回答12.9k 阅读
8 回答2.6k 阅读
2 回答5.1k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
5 回答1.2k 阅读
5 回答1.3k 阅读✓ 已解决
3 回答2.2k 阅读
因为你用 JS 写的就是 focus 的回调啊,系统碰到 focus 当然就会触发回调了,你又没写“失去焦点”时的回调,页面当然乖乖的按照你写的跑啊……可是 CSS 不一样啊,不加伪类时是有默认样式的啊,所以当然一离开就自动还原了嘛……所以说在这种情景下,可能用 CSS 写会相对更加合适一点咯。