jQuery的Textarea的重点 [英] jQuery Textarea focus

查看:163
本文介绍了jQuery的Textarea的重点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击一个按钮时,我希望这个 li 元素中的 textarea 来关注。 b
$ b

 < li class =commentBlockid =commentbox-79style =display:list-item;> 
< div>
< div class =grid userImageBlockS>
< div class =imgSmall>
< img width =35height =35alt =imagesrc =/ bakasura1 / files / images / small / 1288170363aca595cabb50.jpg>
< / div>
< / div>
< div class =grid userContentBlockS alpha omega>
< div style =display:none;>
< input type =hiddenvalue =POSTname =_ method>
< / div>
< input type =hiddenid =StatusMessageReplyPidvalue =79name =data [StatusMessageReply] [pid]>
< input type =hiddenid =StatusMessageReplyItemIdvalue =1name =data [StatusMessageReply] [item_id]>
< input type =hiddenid =StatusMessageReplyCommentersItemIdvalue =1name =data [StatusMessageReply] [commenters_item_id]>
< textarea id =StatusMessageReplyMessagename =data [StatusMessageReply] [message]>
写下您的评论...
< / textarea>
< input type =submitname =value =Commentclass =commentid =comment-79>
< / form>
< / div>
< div class =clear>< / div>
< / div>
< / li>

这是我的 jQuery ($。

$ $ $ $ $''code $('。user-status-buttons')。click(function(){
var id = $(this ).attr('id');
$(#commentbox - + id).slideToggle(fast);
$(#commentbox - + id +#StatusMessageMes​​sage)。 focus();
返回false;
});


解决方案

想要:

  $('。user-status-buttons')。click(function(){

$ id $(this).attr('id');
$(#commentbox - + id).slideToggle(fast,function(){
$ ();
});

return false;
});

这应该给 #StatusMessageReplyMessage 元素焦点 之后幻灯片效果已经完成。


When I click a button I want the textarea in this li element to focus.

<li class="commentBlock" id="commentbox-79" style="display: list-item;">
  <div>
    <div class="grid userImageBlockS">
      <div class="imgSmall">
        <img width="35" height="35" alt="image" src="/bakasura1/files/images/small/1288170363aca595cabb50.jpg">
      </div>
    </div>
    <div class="grid userContentBlockS alpha omega"> 
      <form accept-charset="utf-8" action="/bakasura1/account/saveComment" method="post">
        <div style="display: none;">
          <input type="hidden" value="POST" name="_method">
        </div> 
        <input type="hidden" id="StatusMessageReplyPid" value="79" name="data[StatusMessageReply][pid]"> 
        <input type="hidden" id="StatusMessageReplyItemId" value="1" name="data[StatusMessageReply][item_id]"> 
        <input type="hidden" id="StatusMessageReplyCommentersItemId" value="1" name="data[StatusMessageReply][commenters_item_id]"> 
        <textarea id="StatusMessageReplyMessage" name="data[StatusMessageReply][message]">
          Write your comment...
        </textarea>
        <input type="submit" name="" value="Comment" class="comment" id="comment-79">
      </form> 
    </div>
    <div class="clear"></div>
  </div>
</li>

This is my jQuery code:

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

解决方案

Based on your comment in reply to Jacob, perhaps you want:

$('.user-status-buttons').click(function(){

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

    return false;
});

This should give the #StatusMessageReplyMessage element focus after the slide effect has finished.

这篇关于jQuery的Textarea的重点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆