我是一名新手,并试图创建js脚本来隐藏和在网页上显示可见的部分.以前的部分似乎工作正常.代码段的最后一部分返回此错误:
scripts.js:29 Uncaught TypeError: sections.indexOf is not a function
at nextSection (scripts.js:29)
at <anonymous>:1:1
Run Code Online (Sandbox Code Playgroud)
有谁能告诉我我没有到这里来的?
/*
============================================
array of all sections
============================================
*/
var sections=document.querySelectorAll("section");
/*
============================================
Function to find the section that is being displayed (the one that doesn't have "not1st" as a class.)
============================================
*/
function findSection(){
for (var i=0; i<sections.length; i++) {
if (sections[i].className.includes("not1st")){
continue;
} else {
return sections[i];
}}}
/*
============================================
Function to load the next section
============================================
*/
function nextSection() {
sections[sections.indexOf(findSection())+1];
}
Run Code Online (Sandbox Code Playgroud) 我试图将值 0 存储在关联数组中,以便以后将其用作另一个数组的键。
但是,我无法使用下面的代码检索 0。
发生的情况是,在 while 循环中,当内容为 0 时,它们的“主题”键被完全忽略。
任何其他值都可以。
如何遍历关联数组并获得 0 值?
这种行为的原因是什么?
$requestdata = [];
$requestdata['company'] = 'some company';
$requestdata['country'] = 'some country';
$requestdata['message'] = 'some message';
$requestdata['link'] = 'www.somelink.com';
$requestdata['containers'] = 'some container';
$requestdata['products'] = 'some product';
$requestdata['subject'] = 0;
while (current($requestdata)):
$key = key($requestdata);
if($key != "subject"):
$ncf_values = [];
$ncf_values["fieldValue"] = [];
$ncf_values["fieldValue"]["contact"] = 120;
$ncf_values["fieldValue"]["field"] = 12;
$ncf_values["fieldValue"]["value"] = $requestdata[$key];
elseif($key == "subject"):
$subjects_array = ["Selling","Buying", "Services", "Other"];
$ncf_values = [];
$ncf_values["fieldValue"] = …Run Code Online (Sandbox Code Playgroud)