循环遍历 dom 对象数组并找到第一个匹配的
我的 eform 顶部有一个导航栏,可以跳到下一个和上一个 div(页面/部分),但前提是该 div 可见。除非使用复选框激活,否则 div 是隐藏的。因此,导航栏上的下一个按钮需要始终将您带到下一个可用的 div。
以下代码适用于第一个按钮,但这些导航栏显示在每个部分的顶部,因此下一部分上有一个运行相同功能的下一个按钮(这不起作用),我正在努力在这里解释自己,所以请如果我没有道理就大声喊叫。这是我的代码。
function showNext(){
var pages = [document.getElementById("page2"),document.getElementById("page3")];
var next = ["page2marker","page3marker"];
for (var i=0; i<pages.length; i++){
if(pages[i].style.display == "block"){
window.location.hash = next[i];
}
}
}
我可以修改此功能,使其适用于所有按钮吗?即始终导航到下一个可见的可用 div?我想我可能错过了一个技巧和一大堆信息,但看看你的想法,有什么想法吗?
非常感谢
I have a navigation bar at the top of my eform that skips to the next and previous div (page/section) but only if that div is visible. The divs are hidden unless activated with a checkbox. so the next button on the nav bar needs to work by always taking you to the next available div.
The following code works for the first button but these nav bars display at the top of each section so the next section has a next button on it running the same function (which doesn't work) i'm struggling to exlpain myself here so please shout if i'm not making sense. Here's my code.
function showNext(){
var pages = [document.getElementById("page2"),document.getElementById("page3")];
var next = ["page2marker","page3marker"];
for (var i=0; i<pages.length; i++){
if(pages[i].style.display == "block"){
window.location.hash = next[i];
}
}
}
Can i amend this function so that it will work for all buttons. I.e by always navigating to the next available div that is visible? I think i've probably missed a trick and a whole load of info but see what you think, any ideas?
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 jQuery 和
jQuery.next
函数来实现此目的 - http://api。 jquery.com/next/。对于这样的一组 html:
您可以使用如下内容:
You can achieve this using jQuery with the
jQuery.next
function - http://api.jquery.com/next/.For a set of html like this:
You could use something like: