开发者

focus() not working

I have the following jQuery line:

$('#newStep2 input#name').focus().css('background','Red');

Where I am trying to set the focus of a textbox (#name). I am only setting the background to debug to make sure it works.

Well, the background turns red, but the input is not receiving the focus. Um?

EDIT

HTML, per request:

 <fieldset id="newStep2">
    <h3>2. Name It</h3>            
    <label class="scrollTo">Name:&l开发者_Python百科t;/label>
    <input type="text" name="campaign.name" id="name" />
    <p class="step"><a href="javascript:" class="but_next_step">
         Update and Continue</a></p>
 </fieldset>


from the jquery docs for focus():

This causes all of the functions that have been bound to the focus event to be executed. Note that this does not execute the focus method of the underlying elements.

To call the focus method, either use the each() method to invoke the focus method on each matched element, or use get(index) to get the nth matched element and call the focus method. So either:

$('#newStep2 input#name').each(function() { this.focus();});

or

$('#newStep2 input#name').get(0).focus();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜