在 JavaScript 中检查数组中的值?
我有一个:
var pageURL = location.href; // stores the URL of the current page in the var pageURL
我有:
var Page = Array ();
page [0] = "http://web1.com"
page [1] = "http://web2.com"
page [2] = "http://web3.com"
现在我想做一个函数(称为 nextPage)来检查数组中的哪一个页面等于 PageURL。我还需要一个按钮,所以当我单击它时,它将带我进入下一页。这意味着我想将页面增加 1。
I have a:
var pageURL = location.href; // stores the URL of the current page in the var pageURL
And I have :
var Page = Array ();
page [0] = "http://web1.com"
page [1] = "http://web2.com"
page [2] = "http://web3.com"
Now I want to make a function (called nextPage) to check which one of these pages in the array equals the PageURL. Also I need to have a button, so when I click it it will take me to the next page. What that mean I want to increment the page by 1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以非常简单地使用
Then 转到下一页
You can use very simply
Then to go to the next page
根据 Joseph 的回答,完整的代码将如下所示:
另外,如果 IE 中对 indexOf 的支持对您来说是一个问题,请查看另一个 StackOverflow 问题的答案: 如何在 Internet Explorer 浏览器的 JavaScript 中修复 Array indexOf()
Based on Joseph's answer the full code would look something like this:
Also if support for indexOf is an issue for you in IE check out the answer to that from another StackOverflow question: How to fix Array indexOf() in JavaScript for Internet Explorer browsers