问题
Is anyone using tokeninput plugin and successfully setting focus on a token input field? I'm trying to achieve this.
Solved: In case anyone else needs, the solution:
$(document).ready(function() {
$("#YourTokenInput").tokenInput("http://shell.loopj.com/tokeninput/tvshows.php",
{ theme: "facebook"
}).focus();
});
回答1:
OP's solution didn't work for me. Not sure if it is a browser issue, or a issue with the elements being loaded in time, or what, but this is what I had to do (after initializing the token input:
setTimeout(function() { $('#token-input-search-input').focus(); }, 50);
Note: (testing in Chrome)
来源:https://stackoverflow.com/questions/10341035/jquery-tokeninput-plugin-and-focus