简体   繁体   English

为什么当我在页面顶部滚动并单击附加表格的链接时,它会向下滚动

[英]Why when i scroll top my page and click link which append a form it scroll me down

i have a page that show activity feeds with a comment link for each feed, i add a comment form dynamically like this : 我有一个页面显示活动供稿,每个供稿都带有评论链接,我像这样动态添加评论表:

$("#feedList").on("click", ".comment-link", function(e){
        $(this).parent().append('<form method="post" action="#" class="commentForm"><p><textarea class="comment"></textarea></p><p><input type="submit" value="add" class="send-Comment-Btn" /></p></form>');
        $("textarea.comment").select();
        return false;
    }); 

when i scroll down my page and i click in some comment link it shows me the form as expected, but if i scroll to the top of the page again and i try to click a comment link it shows the form too but it scroll me to the bottom page to the last link i have clicked before, someone can tell me why this behavior and solution for this ? 当我向下滚动页面并单击一些评论链接时,它会按预期显示表单,但是,如果我再次滚动至页面顶部,并且尝试单击评论链接,它也会显示该表单,但会滚动至我之前单击过的最后一个链接的底部页面,有人可以告诉我为什么这种行为和解决方案?

$("textarea.comment").select();

will always move you to first created textarea element with class "comment". 将始终将您带到第一个创建的带有“ comment”类的textarea元素。 Maybe you must add some ID that increments every click like: 也许您必须添加一些ID,以增加每次点击的次数,例如:

var someID = 0;
$("#feedList").on("click", ".comment-link", function(e){
someID += 1;
        $(this).parent().append('<form method="post" action="#" class="commentForm"><p><textarea class="comment" id="selectorForComment' + someID + '"></textarea></p><p><input type="submit" value="add" class="send-Comment-Btn" /></p></form>');
        $("#selectorForComment" + someID).select();
        return false;
    }); 

暂无
暂无

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

相关问题 完美滚动到顶部。 但是当我向下滚动并单击页面上的任意位置时,滚动再次移至顶部 - Perfectly scroll to top. but when i scroll down and click anywhere on page, again scroll moves to the top 为什么向下滚动时不重新加载数据,而在无限滚动中返回页面顶部时为什么不重新加载数据? - Why do not I reload the data when I scroll down and do it when I go back to the top of the page in my infinite scroll? 我希望页面向下滚动,当我的 cursor 接近页面顶部或底部时自动顶部 - I want the page to scroll down, top automatically when my cursor is near the top or bottom of the page 为什么我的页面顶部按钮在我的 API 应用程序上滚动到顶部然后返回时会卡顿/滞后/粘滞,但在网页上却正常运行? - Why does my top of page button stutter/lag/stick when I scroll to top and then back down on my API app but acts normal on webpages? 当我点击图片时如何让我的网站滚动到顶部 - How to get my website to scroll to the top when I click on an image 向下滚动页面时突出显示导航链接 - Highlight navigation link as i scroll down the page 如何获得锚链接,使其在向下滚动时像在其上一样平滑地向上滚动? - How can I get my anchor link to scroll smoothly back up top like it does when it goes down? 当我单击链接时,我的网站总是向上滚动吗? - My website alway scroll up when i click link? 为什么当我将 div 向下移动到页面时滚动条会滚动 - why does the scrollbar scroll when I move the div down to the page 滚动到顶部,动画滚动到#page链接冲突 - Scroll to top and animated scroll to #page link conflict
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM