简体   繁体   English

滚动到文本区域后如何添加焦点?

[英]how do I add focus to a textarea after scrolling to it?

I am using the following script to scroll to the top of a scrolling DIV when a link is clicked: 单击链接时,我正在使用以下脚本滚动到滚动DIV的顶部:

<script type="text/javascript" src="jquery.js"></script>
    <script>
    function goToByScroll(id){
            $('#disqus_thread').animate({scrollTop: $("#"+id).position().top},3000,'easeOutQuint');
    }
</script>

Here's the html for the link: 这是链接的html:

   <div id="commenttext"><a href="javascript:void(0)" onClick="goToByScroll('top')"><img src="files/comment.png" class="imgHoverable"></a></div>

I would like the textarea that is underneath the DIV that is scrolled to to have the focus added to it after the scroll. 我希望滚动到DIV下方的文本区域在滚动后将焦点添加到该区域。 I presume this would mean adding code something like this: 我认为这意味着添加如下代码:

$("textarea.placeholder").focus();

But I am not sure how to include this in the above script. 但是我不确定如何在上面的脚本中包括它。 I tried adding it as a line at the end of the script, but it didn't work. 我尝试在脚本末尾将其添加为一行,但是没有用。

Could someone help me out with this? 有人可以帮我这个忙吗?

Thanks, 谢谢,

Nick 缺口

function goToByScroll(id){
  $('#disqus_thread')
   .animate({scrollTop: $("#"+id).position().top},
            3000,
            'easeOutQuint', 
            function() { $("textarea.placeholder").focus(); }
   );
}

The last argument when passed this way is the complete callback. 通过这种方式传递的最后一个参数是完整的回调。

Documentation . 文件资料

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM