开发者

Javascript de-focus textfield input

开发者 https://www.devze.com 2023-02-03 11:25 出处:网络
I have a modal that I pop up with jQuery with a textfield on which I want to trigger the focus() event.

I have a modal that I pop up with jQuery with a textfield on which I want to trigger the focus() event.

Problem is the fextfield IS allready focused.. In most browsers it is even highlighted. (I have no idea why?)

How can I de-focus or de-select the text so I can use the focus() event?

<input type="text" class="shortcut" id="input-shortcut" value="<?= $shortcut_url; ?>" />

$(".shortcut").focus(function开发者_JAVA百科() { 
    $(this).addClass("focus");
    $(this).select();
}).blur(function() { 
    $(this).removeClass("focus"); 
});


Use $("#element").blur();

jQuery documentation of blur


Use Jquery's blur() function. Which is basically like "out of focus"

0

精彩评论

暂无评论...
验证码 换一张
取 消