我正在使用 Ajax 加载表单的各个部分。如何在ajax请求后聚焦textarea对象?
这是加载的 html:
<legend>Test</legend>
<label for="t">This is only a test</label>
<textarea></textarea>
<a href="#" class="continue">Continue</a>
这是 JQuery/Ajax 代码:
$.post(
'ajax.php',
{ next:next },
function(data){
$('body').append($(data).hide().fadeIn('slow'));
}
);
谢谢。
最佳答案
附加 html 后,在回调中使用 .focus() 触发器:
$.post(
'ajax.php',
{ next:next },
function(data){
$('body').append($(data).hide().fadeIn('slow'));
$('textarea').focus();
}
);
关于JQuery:ajax加载后聚焦文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7955408/