我想在我的页面上添加“ADD COMMENT”按钮。 所以onClick我正在显示表单来添加评论。 我希望表单在页面的顶部位置滚动,因此用户无需向下滚动即可查看所有注释。
<script>function showDiv() {
var div = document.getElementById('comdiv');
var button = document.getElementById('button');
if (div.style.display !== "none") {
div.style.display = "none";
button.value = "Add Comments";
}
else {
button.value = "Hide Comments";
div.style.display = "block";
}
}</script>`<input type="button" id="button" name="answer" value="Add Comments" onclick="showDiv()" autofocus />
<div id="comdiv" style="display:none;" class="answer_list" >
<form name="form" id="form" action="" method="post">
<p class="h5">Comment</p>
<textarea name="comment" id="comment" placeholder="Write Comment, Max: 140 characters" rows="4" class="width-50" onblur="checkMe()" ></textarea>
<span class="forms-desc">Comments should atleast have 20 character's</span><br/>
<button type="submit" name="submit" id="submitbutton" class="btn btn-green btn-outline" disabled="disabled">Post Comment</button>
</form></div>`
答案 0 :(得分:1)
将此代码用于您的&#34;脚本&#34;标签
$(&#39;#button&#39;)。点击(function(){
$('html,body').animate({scrollTop: '0px'}, 1000);
});
答案 1 :(得分:0)
添加onclick =&#34; goTop()&#34;
并定义
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Parent{
private String name;
private String surname;
}
答案 2 :(得分:0)
scrollIdIntoView("comment-1");
function scrollIdIntoView(id,speed) {
if ($('#'+id).length) {
$('html,body').animate({
scrollTop : $('#'+id).offset().top - 30
}, speed);
$('#'+id).show().focus().click();
return false;
};
};
答案 3 :(得分:0)
$('button').click(function() {
$('html, body').animate({
scrollTop: '0px'
});
});
li {
list-style: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
<li>comment1</li>
</ul>
<button>Comment</button>
答案 4 :(得分:-2)