How to save a variable javascript? [closed]

此生再无相见时 提交于 2019-12-25 07:00:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!