【发布时间】:2009-09-16 15:33:23
【问题描述】:
将焦点设置到动态加载的 DIV 中的特定字段的正确方法是什么?
$("#display").load("?control=msgs"); // loads the HTML into the DIV
$('#display').fadeIn("fast"); // display it
$("tex#header").focus(); // ?? neither that
$("input#header").focus(); // ?? nor that
$('#display', '#header').focus() // ?? nor that
$("#header").focus(); // ?? nor that works
以下 HTML 被提取到 display DIV:
<div id="display">
<form id="newHeaderForm" class="dataform" action="/" method="post">
<input id="to" type="hidden" value="22" name="to"/>
<dl>
<dt>Header</dt>
<dd>
<input id="header" class="large" type="text" name="header" value="" maxlength="128"/>
</dd>
</form>
</div>
非常感谢!
【问题讨论】:
-
你能不能给我们看看生成的html?
-
$('#display', '#header').focus() 应该可以工作
标签: jquery html focus setfocus