[英]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.