综合开发

Entry does not add class when it is concentrated

微信扫一扫,分享到朋友圈

Entry does not add class when it is concentrated

I have this extremely
simple click event, where if the input
has been focused, it is supposed to add a class to said input
.

However, it doesn’t want to add the class. I have been sure to include the jQuery
library, but nothing happens.

jQuery:

$("body").on("click", function(){
if($("input").is(":focus")){
$(this).addClass("highlight-input");
} else {
$(this).removeClass("highlight-input");
}
});

You need to use this way:

$(document).ready(function () {
$("input").on("focus", function () {
$(this).addClass("highlight-input");
}).on("blur", function () {
$(this).removeClass("highlight-input");
});
});

余承东:4 月 8 日华为 P40/Pro 中国发布会上将首发大招

上一篇

Android静态广播多action冲突

下一篇

你也可能喜欢

评论已经被关闭。

插入图片

热门栏目

Entry does not add class when it is concentrated

长按储存图像,分享给朋友