Javascript de-focus textfield input
I have a modal that I pop up with jQuery with a textfield on which I want to trigger the focus()
event.
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"
精彩评论