为什么我不能模拟焦点?

时间:2015-11-16 16:24:03

标签: jquery input focus

这是我的代码:

$(document).ready(function () {
    $(".boxForm .inputForm").focusin(function () {
        $(this).parent().addClass("focused");
    });
    $(".boxForm .inputForm").focusout(function () {
        if ($(this).val() == "") {
            $(this).parent().removeClass("focused");
        }
    });

    $(".boxForm .inputForm").each(function () {
        var inputSel = $(this);
        inputSel.trigger("focusin");
        inputSel.trigger("focusout");
    });
});

当我加载页面时,我想模拟focusin / out(因此我可以保持当前状态,即使输入值由浏览器本身自动完成)。

它不会触发这些事件(例如,如果输入为空或填充,则不会添加/删除该类focused

0 个答案:

没有答案
相关问题