我有以下jQuery行:
$('#newStep2 input#name').focus().css('background','Red');在这里,我试图设置文本框(#name)的焦点。我只是将背景设置为调试,以确保其工作正常。
嗯,背景变红了,但是输入没有收到焦点。恩?
编辑
HTML,每个请求:
<fieldset id="newStep2">
<h3>2. Name It</h3>
<label class="scrollTo">Name:</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>发布于 2009-10-05 23:28:27
从jquery文档中获取focus():
--这会导致所有绑定到焦点事件的函数都被执行。请注意,这不会执行基础元素的焦点方法。
要调用focus方法,可以使用each()方法对每个匹配元素调用focus方法,或者使用get(index)获取第n个匹配元素并调用focus方法。因此,要么是:
$('#newStep2 input#name').each(function() { this.focus();});或
$('#newStep2 input#name').get(0).focus();https://stackoverflow.com/questions/1522887
复制相似问题