![](/img/trans.png)
[英]How to focus on a particular portion of an another html page when click on a button or link
[英]How to focus on a particular portion of a web page using javascript?
有人可以通過使用javascript事件告訴我如何關注網頁的特定部分嗎? 假設我單擊了一個按鈕,它將向下滾動或向上滾動到頁面的特定部分。 這是我不完整的代碼:
<html>
<head>
<script type="text/javascript">
function focusOnForm() {
document.getElementById('form').style.display = '';
}
</script>
</head>
<body onload="document.getElementById('form').style.display = 'none';">
<div style="height: 900px; width: width: 500px; background-color: #000;">
</div>
<br />
<input type="button" value="Add" style="float: right;" onclick="focusOnForm();" />
<br />
<div id="form">
First Name: <input type="text" /> <br />
Last Name: <input type="text" /> <br />
Address: <input type="text" /> <br />
Contact Number: <input type="text" /> <br />
Email: <input type="text" /> <br />
</div>
</body>
</html>
我真的需要幫助。 提前致謝。
使用.scrollIntoView()
方法:
function focusOnForm() {
var form = document.getElementById('form');
form.style.display = '';
form.scrollIntoView();
}
小提琴: http : //jsfiddle.net/g8Mqr/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.