Uncaught SyntaxError: Unexpected end of input for particles.js
Uncaught SyntaxError: Unexpected end of input for particles.js
我在使用 particles.js 时收到未捕获的语法错误:第 36 行的输入意外结束。
代码:https://jsfiddle.net/30qtvprj/
代码的主要问题部分(触发错误的地方):
particlesJS("particles-js", resp);
var count_particles, stats, update;
stats = new Stats();
stats.setMode(0);
stats.domElement.style.position = "absolute";
stats.domElement.style.left = "0px";
stats.domElement.style.top = "0px";
document.body.appendChild(stats.domElement);
count_particles = document.querySelector(".js-count-particles");
update = function() {
stats.begin();
stats.end();
if (window.pJSDom[0].pJS.particles && window.pJSDom[0].pJS.particles.array) {
count_particles.innerText = window.pJSDom[0].pJS.particles.array.length;
}
requestAnimationFrame(update);
};
requestAnimationFrame(update);
我认为您的 jsonstuffs 需要像这样的对象:
var jsonstuffs = {
setData: function (key, obj) {
var values = JSON.stringify(obj);
localStorage.setItem(key, values);
},
getData: function (key) {
if (localStorage.getItem(key) != null) {
return JSON.parse(localStorage.getItem(key));
} else {
return false;
}
},
updateDate: function (key, newData) {
if (localStorage.getItem(key) != null) {
var oldData = JSON.parse(localStorage.getItem(key));
for (keyObj in newData) {
oldData[keyObj] = newData[keyObj];
}
var values = JSON.stringify(oldData);
localStorage.setItem(key, values);
} else {
return false;
}
}
}
我在使用 particles.js 时收到未捕获的语法错误:第 36 行的输入意外结束。
代码:https://jsfiddle.net/30qtvprj/
代码的主要问题部分(触发错误的地方):
particlesJS("particles-js", resp);
var count_particles, stats, update;
stats = new Stats();
stats.setMode(0);
stats.domElement.style.position = "absolute";
stats.domElement.style.left = "0px";
stats.domElement.style.top = "0px";
document.body.appendChild(stats.domElement);
count_particles = document.querySelector(".js-count-particles");
update = function() {
stats.begin();
stats.end();
if (window.pJSDom[0].pJS.particles && window.pJSDom[0].pJS.particles.array) {
count_particles.innerText = window.pJSDom[0].pJS.particles.array.length;
}
requestAnimationFrame(update);
};
requestAnimationFrame(update);
我认为您的 jsonstuffs 需要像这样的对象:
var jsonstuffs = {
setData: function (key, obj) {
var values = JSON.stringify(obj);
localStorage.setItem(key, values);
},
getData: function (key) {
if (localStorage.getItem(key) != null) {
return JSON.parse(localStorage.getItem(key));
} else {
return false;
}
},
updateDate: function (key, newData) {
if (localStorage.getItem(key) != null) {
var oldData = JSON.parse(localStorage.getItem(key));
for (keyObj in newData) {
oldData[keyObj] = newData[keyObj];
}
var values = JSON.stringify(oldData);
localStorage.setItem(key, values);
} else {
return false;
}
}
}