问题
So im running this script and i want to be able to save the variable stopNumber after the script is finished running so that the next time i run this script the saved variable stopNumber can be set to the variable loops so that i dont have to manually set it all the time.
var loops = Number(prompt("Starting csv line?"));
var stopNumber = loops + 15;
for (csvLine = loops ; csvLine <= stopNumber ; csvLine++) {
iimSet ("-var_CSVLINE", csvLine);
iimPlay("Testing.iim");
}
回答1:
You can store the value in local storage
localStorage.setItem("stopNumber", stopNumber);
Retrieve it with
stopNumber = parseInt(localStorage.getItem("stopNumber"));
More info here http://www.w3schools.com/html/html5_webstorage.asp
回答2:
try to use localStorage.
Like: localStorage.stopNumber = stopNumber;
you may call it as localStorage.stopNumber
回答3:
Try this:
function doSomething() {
var loops = doSomething.stopNumber || Number(prompt("Starting csv line?"));
doSomething.stopNumber || doSomething.stopNumber = loops + 15;
for (csvLine = loops ; csvLine <= stopNumber ; csvLine++) {
iimSet ("-var_CSVLINE", csvLine);
iimPlay("Testing.iim");
}
}
来源:https://stackoverflow.com/questions/27754366/how-to-save-a-variable-javascript