Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript查询修复程序_Javascript_Html_Arrays - Fatal编程技术网

Javascript查询修复程序

Javascript查询修复程序,javascript,html,arrays,Javascript,Html,Arrays,我是Javascript编程新手,有人能帮我修复下面的脚本吗。在这个脚本中,我从用户那里获得一些输入,然后将其添加到一个数组中。最后在表中显示它。但由于某种原因,数组中的最后一个条目将覆盖其中以前的所有条目 var CountryList=new Array(); var-arrNum=0; 国家职能(名称、首都){ this.name=名称; 这个资本=资本; //评论 //警报(arrNum); CountryList.push(这个); document.getElementsByNam

我是Javascript编程新手,有人能帮我修复下面的脚本吗。在这个脚本中,我从用户那里获得一些输入,然后将其添加到一个数组中。最后在表中显示它。但由于某种原因,数组中的最后一个条目将覆盖其中以前的所有条目

var CountryList=new Array();
var-arrNum=0;
国家职能(名称、首都){
this.name=名称;
这个资本=资本;
//评论
//警报(arrNum);
CountryList.push(这个);
document.getElementsByName(“countryName”)[0]。value=“”;
document.getElementsByName(“capitalCity”)[0]。value=“”;
}
函数funcSaveButton(){
var txt1=document.getElementsByName(“countryName”)[0];
var txt2=document.getElementsByName(“capitalCity”)[0];
initCountry(txt1.value,txt2.value);
//警报(txt1.value+“:”+txt2.value);
arrNum++;
}
函数displayList(){
var i;
文件。填写(“”);
文件。填写(“国家名称首都”)
对于(i=0;i
国家名称:

首都:


您正在将窗口对象推送到CountryList 在函数内部,这个对象是窗口。 使用这个
CountryList.push({name:name,capital:capital})

var CountryList=new Array();
var-arrNum=0;
国家职能(名称、首都)
{
this.name=名称;
这个资本=资本;
//评论
//警报(arrNum);
push({name:name,capital:capital});
document.getElementsByName(“countryName”)[0]。value=“”;
document.getElementsByName(“capitalCity”)[0]。value=“”;
}
函数funcSaveButton()
{
var txt1=document.getElementsByName(“countryName”)[0];
var txt2=document.getElementsByName(“capitalCity”)[0];
initCountry(txt1.value,txt2.value);
//警报(txt1.value+“:”+txt2.value);
arrNum++;
}
函数displayList()
{   
console.log(CountryList);
var i;
文件。填写(“”);
文件。填写(“国家名称首都”)

对于(i=0;i您正在将窗口对象推送到CountryList 在函数内部,这个对象是窗口。 使用这个
CountryList.push({name:name,capital:capital});

var CountryList=new Array();
var-arrNum=0;
国家职能(名称、首都)
{
this.name=名称;
这个资本=资本;
//评论
//警报(arrNum);
push({name:name,capital:capital});
document.getElementsByName(“countryName”)[0]。value=“”;
document.getElementsByName(“capitalCity”)[0]。value=“”;
}
函数funcSaveButton()
{
var txt1=document.getElementsByName(“countryName”)[0];
var txt2=document.getElementsByName(“capitalCity”)[0];
initCountry(txt1.value,txt2.value);
//警报(txt1.value+“:”+txt2.value);
arrNum++;
}
函数displayList()
{   
console.log(CountryList);
var i;
文件。填写(“”);
文件。填写(“国家名称首都”)

对于(i=0;i
document.write()
在加载完成后覆盖整个文档。简而言之,不要使用it@SterlingArcher很抱歉,这不是我的查询,我也知道。但是数组的最后一个条目正在覆盖整个数组。
document.write()
加载完成后将覆盖整个文档。简而言之,不要使用it@SterlingArcher很抱歉,这不是我的查询,我也知道。但是数组的最后一个条目正在覆盖整个数组。