我的 javascript 有问题,我需要在我的 html 文档中找到 div 的最后一个 id。我可以通过查看它来找到它,但我希望它在 JavaScript 中是自动的。
<body>
<div id="start">
<div id="1">Text</div>
<div id="2">Text</div>
<div id="3">Text</div>
<div id="4">Text</div>
<div id="5">Text</div>
<div id="6">Text</div>
</div>
</body>
javascript:
function setCookie() {
document.cookie = '1';
}
function startPage() {
var cookieValueInt = parseInt(document.cookie);
var secondPage = cookieValueInt + 1;
document.getElementById(document.cookie).style.visibility = 'visible';
document.getElementById(secondPage).style.visibility = 'visible';
if (cookieValueInt == 1) {
document.getElementById('leftarrow').style.visibility = 'hidden';
}
}
function nextPage() {
var cookieValueInt = parseInt(document.cookie);
var secondPage = cookieValueInt + 1;
var newCookieValue = cookieValueInt + 2;
document.getElementById(document.cookie).style.visibility = 'hidden';
document.getElementById(secondPage).style.visibility = 'hidden';
document.getElementById(newCookieValue).style.visibility = 'visible';
document.getElementById(newCookieValue + 1).style.visibility = 'visible';
document.getElementById('leftarrow').style.visibility = 'visible';
document.cookie = newCookieValue;
}
function previousPage() {
var cookieValueInt = parseInt(document.cookie);
var secondPage = cookieValueInt + 1;
var newCookieValue = cookieValueInt - 2;
document.getElementById(document.cookie).style.visibility = 'hidden';
document.getElementById(secondPage).style.visibility = 'hidden';
document.getElementById(newCookieValue).style.visibility = 'visible';
document.getElementById(newCookieValue + 1).style.visibility = 'visible';
document.cookie = newCookieValue;
cookieValueInt = parseInt(document.cookie);
if (cookieValueInt == 1) {
document.getElementById('leftarrow').style.visibility = 'hidden';
}
}