开发者

How do you automatically set focus on a form field using yui

开发者 https://www.devze.com 2023-04-06 18:42 出处:网络
I currently have an issuewhere I want text field to be automatically selected when the us开发者_开发技巧er visits mywebpage, I currentlydo thisbyJavascriptbutwould, ideally, like to use YUI. After sea

I currently have an issue where I want text field to be automatically selected when the us开发者_开发技巧er visits my webpage, I currently do this by Javascript but would, ideally, like to use YUI. After searching the web, i found this command,

YAHOO.util.Dom.get("first_element").focus();

and

YAHOO.util.Dom.get("text1t").focus();

but have had very little luck getting it to work, one suggestion was to use a setTimeout fnction, but this seems a rather ugly way of doing it.

If anyone has any suggstions I would be very grateful.

Thanks,


Try using onAvailable

YAHOO.util.Event.onAvailable("elementId", function(me) { me.focus(); }, YAHOO.util.Dom.get("elementId"));

You may need to use a later event, like onContentReady or even onDOMReady if that doesn't work.

0

精彩评论

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