当我专注于表格时,我已经有了这个小脚本来切换快乐的脸:
/* Happy face script */
$('#search').on('focusin', function() {
$("#smile").removeClass("fa-meh-o");
$("#smile").addClass("fa-smile-o");
});
$('#search').on('focusout', function() {
$("#smile").removeClass("fa-smile-o");
$("#smile").addClass("fa-meh-o");
});
然而,当我click 'submit'
时,它会回到focusout
状态。我该如何避免呢?
答案 0 :(得分:0)
删除focusoutevent
并使用toggleClass()之类的,
$('#search').on('focusin', function() {
$("#smile").toggleClass("fa-meh-o fa-smile-o");
});
$('#submit')on('click',function(){
// your code then you can remove the classes again if not then remove below code
$("#smile").toggleClass("fa-meh-o fa-smile-o");
});
已更新您可以focusin and focusout
使用相同的toggleClass
,
$('#search').on('focusin focusout', function() {
$("#smile").toggleClass("fa-meh-o fa-smile-o");
});