开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜