Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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 如何在.txt中打印特定的数据属性_Javascript_Jquery_Json - Fatal编程技术网

Javascript 如何在.txt中打印特定的数据属性

Javascript 如何在.txt中打印特定的数据属性,javascript,jquery,json,Javascript,Jquery,Json,我有一个css网格,其中的框一旦被点击,就会从白色变为红色,然后变为绿色,并且可以返回到初始状态。它还有一个数据属性(每个框),根据框的点击情况,从defaultWhite状态变为defaultRed和defaultGreen。现在,我想打印一个带有选项的.txt报告。我已经研究并编写了一些代码,但现在不起作用 目标: 单击下载按钮后,将获得一个.txt表,其中包含所有52个框的所有值及其数据(默认值,如果为红色或绿色) readyfunction下载(文件名、状态数据){ var-ele

我有一个css网格,其中的框一旦被点击,就会从白色变为红色,然后变为绿色,并且可以返回到初始状态。它还有一个数据属性(每个框),根据框的点击情况,从defaultWhite状态变为defaultRed和defaultGreen。现在,我想打印一个带有选项的.txt报告。我已经研究并编写了一些代码,但现在不起作用

目标:

  • 单击下载按钮后,将获得一个.txt表,其中包含所有52个框的所有值及其数据(默认值,如果为红色或绿色)
readyfunction下载(文件名、状态数据){
var-element=document.createElement('a');
element.setAttribute('href','data:text/plain;charset=utf-8',+encodeURIComponent(text));
setAttribute('download',filename);
element.style.display='none';
document.body.appendChild(元素);
元素。单击();
document.body.removeChild(元素);
}
//开始文件下载。
document.getElementById(“dwn btn”).addEventListener(“单击”,函数(){
//生成包含一些内容的hello.txt文件的下载
var text=document.getElementById(“sheW1”);
var stateData=text.getAttribute('data');
var filename=“Report.txt”;
下载(文件名、状态数据);
},假)
html{
-webkit字体平滑:抗锯齿;
}
身体{
背景:#fff;
保证金:0自动;
填充:1em;
-webkit用户选择:无;/*Chrome all/Safari all*/
-moz用户选择:无;/*Firefox全部*/
-ms用户选择:无;/*IE 10+*/
用户选择:无;
}
.generalWrapper{
显示器:flex;
弯曲方向:立柱;
证明内容:中心;
对齐项目:居中;
宽度:100%;
背景色:;
职位:
}
.box集装箱{
显示器:flex;
弯曲方向:行;
证明内容:中心;
对齐项目:居中;
宽度:1280px;
背景色:;
}
.网格容器{
显示:网格;
网格模板柱:1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
网格模板行:1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
网格模板区域:“标题标题标题”sheW1 sheW2 sheW3 sheW4 sheW5 sheW6 sheW7 sheW8 sheW9 sheW10 sheW11 sheW12 sheW13 sheW14“sheW52字母sheW15”“sheW51字母sheW16”“sheW50字母sheW17”“sheW49字母sheW18”sheW48字母sheW19“sheW47字母sheW20”sheW46字母sheW21sheW45字母sheW22“sheW44字母sheW23”sheW43字母sheW24sheW42字母sheW25字母sheW41字母sheW26字母sheW40 sheW39 sheW38 sheW37 sheW36 sheW35 sheW34 sheW33 sheW32 sheW31 sheW30 sheW29 sheW28 sheW27;
宽度:300px;
高度:320px;
字体系列:无衬线,helvetica;
背景色:白色;
背景色:;
}
.头衔{
网格区域:标题;
文本对齐:居中;
背景色:深蓝色;
颜色:白色;
字号:1em;
填充:5px0px;
字号:600;
}
#sheW1{网格区域:sheW1;
文本对齐:居中;
}
#sheW2{网格区域:sheW2;
文本对齐:居中;
}
#sheW3{网格区域:sheW3;
文本对齐:居中;
}
#sheW4{网格区域:sheW4;
文本对齐:居中;
}
#sheW5{网格区域:sheW5;
文本对齐:居中;
}
#sheW6{网格区域:sheW6;
文本对齐:居中;
}
#sheW7{网格区域:sheW7;
文本对齐:居中;
}
#sheW8{网格区域:sheW8;
文本对齐:居中;
}
#sheW9{网格区域:sheW9;
文本对齐:居中;
}
#sheW10{网格区域:sheW10;
文本对齐:居中;
}
#sheW11{网格区域:sheW11;
文本对齐:居中;
}
#sheW12{网格区域:sheW12;
文本对齐:居中;
}
#sheW13{网格区域:sheW13;
文本对齐:居中;
}
#sheW14{网格区域:sheW14;
文本对齐:居中;
}
#sheW15{网格区域:sheW15;
文本对齐:居中;
}
#sheW16{网格区域:sheW16;
文本对齐:居中;
}
#sheW17{网格区域:sheW17;
文本对齐:居中;
}
#sheW18{网格区域:sheW18;
文本对齐:居中;
}
#sheW19{网格区域:sheW19;
文本对齐:居中;
}
#sheW20{网格区域:sheW20;
文本对齐:居中;
}
#sheW21{网格区域:sheW21;
文本对齐:居中;}
#sheW22{网格区域:sheW22;
文本对齐:居中;
}
#sheW23{网格区域:sheW23;
文本对齐:居中;
}
#sheW24{网格区域:sheW24;
文本对齐:居中;
}
#sheW25{网格区域:sheW25;
文本对齐:居中;}
#sheW26{网格区域:sheW26;
文本对齐:居中;
}
#sheW27{网格区域:sheW27;
文本对齐:居中;
}
#sheW28{网格区域:sheW28;
文本对齐:居中;
}
#sheW29{网格区域:sheW29;
文本对齐:居中;
}
#sheW30{网格区域:sheW30;
文本对齐:居中;
}
#sheW31{网格区域:sheW31;
文本对齐:居中;
}
#sheW32{网格区域:sheW32;
文本对齐:居中;
}
#sheW33{网格区域:sheW33;
文本对齐:居中;
}
#sheW34{网格区域:sheW34;
文本对齐:居中;
}
#sheW35{网格区域:sheW35;
文本对齐:居中;
}
#sheW36{网格区域:sheW36;
文本对齐:居中;
}
#