p5.js中的clearStorage()函數用於使用storeItem()函數清除本地存儲集中存在的所有項目。當前域中的項目已刪除。現在嘗試使用getItem()函數檢索任何項目將返回null。它不接受任何參數。
用法:
clearStorage()
參數:此函數不接受任何參數。
以下程序說明了p5.js中的clearStorage()函數:
例:
function setup() {
createCanvas(400, 300);
textSize(16);
text("Use the button to set and"+
" retrieve random values", 20, 20);
setBtn = createButton("Set items to storage");
setBtn.position(20, 150);
setBtn.mouseClicked(setItems);
getBtn = createButton("Get items from storage");
getBtn.position(20, 180);
getBtn.mouseClicked(getItems);
clearBtn = createButton("Clear items from storage");
clearBtn.position(20, 210);
clearBtn.mouseClicked(clearItems);
}
function clearItems() {
clear();
text("Use the button to set and retrieve"+
" random values", 20, 20);
text("Storage Cleared!", 20, 40);
// Clear all items in storage
clearStorage();
}
function getItems() {
clear();
text("Use the button to set and retrieve"+
" random values", 20, 20);
// Retrieve values from local storage
id = getItem("savedNumber");
author = getItem("savedString");
isBestseller = getItem("savedBoolean");
// Display the values
text("The retrieved items are:", 20, 40);
text("Book ID:" + id, 20, 60);
text("Author:" + author, 20, 80);
text("Bestseller:" + isBestseller, 20, 100);
}
function setItems() {
clear();
text("Use the button to set and retrieve"+
" random values", 20, 20);
text("Random items set!", 20, 40);
// Generate random values
randomID = floor(random(100));
randomAuthor = "Author " + randomID;
randomBool = randomID > 50 ? true :false;
// Store values to local storage
storeItem("savedNumber", randomID);
storeItem("savedString", randomAuthor);
storeItem("savedBoolean", randomBool);
}
輸出:
參考: https://p5js.org/reference/#/p5/clearStorage
在線編輯: https://editor.p5js.org/
環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
參考: https://p5js.org/reference/#/p5/rectMode
相關用法
- PHP Ds\Map xor()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- p5.js pan()用法及代碼示例
- p5.js value()用法及代碼示例
- p5.js mag()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP ord()用法及代碼示例
- p5.js nfs()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js nfp()用法及代碼示例
- p5.js box()用法及代碼示例
- p5.js nfc()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- p5.js nf()用法及代碼示例
- d3.js d3.set.add()用法及代碼示例
- p5.js arc()用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.js | clearStorage() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。