jQuery Textarea重点

当我单击一个按钮时,我希望此li元素中的textarea能够聚焦。

 
  • image
  • 这是我的jQuery代码:

     $('.user-status-buttons').click(function() { var id = $(this).attr('id'); $("#commentbox-"+id).slideToggle("fast"); $("#commentbox-"+id+" #StatusMessageMessage").focus(); return false; }); 

    根据您对雅各布的回复,也许您想要:

     $('.user-status-buttons').click(function(){ var id = $(this).attr('id'); $("#commentbox-"+id).slideToggle("fast", function(){ $("#commentbox-"+id+" #StatusMessageReplyMessage").focus(); }); return false; }); 

    这应该在幻灯片效果完成#StatusMessageReplyMessage元素焦点。

    我使用计时器来聚焦文本区域:

     setTimeout(function() { $el.find('textarea').focus(); }, 0); 
      $('#StatusMessageReplyMessage').focus();