【IDBObjectStore】.add( 連想配列 );
【IDBObjectStore】.put( 連想配列 );
transaction("mydata",IDBTransaction.READ_WRITE);【IDBObjectStore】.delete( キーの値 );
var data = { name: nstr, email: estr, tel:tstr };
var objectStore = db.transaction([],IDBTransaction.READ_WRITE).
objectStore("mydata");
objectStore.put(data);※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8">
<title>Sample</title>
<style>
h1 {font-size: 14pt; font-weight:bold;
background-color:#DDF; padding:3px; }
#ftable tr td { background-color:#CFC; }
#datas tr td { background-color:#FCC; }
</style>
<script type="text/javascript">
var IDBTransaction;
var IndexedDB;
var db;
var objectStore;
function initial(){
IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
try {
IndexedDB = mozIndexedDB;
} catch(e){}
try {
IndexedDB = webkitIndexedDB;
} catch(e){}
var request = IndexedDB.open("MyTestDatabase");
request.onerror = function(event) {
alert("ERROR!");
};
request.onsuccess = function(event) {
db = request.result;
createObjectStoreMethod();
//alert("OK!");
};
}
function createObjectStoreMethod(){
var request = db.setVersion("1.0");
request.onerror = function(event) { /* ERROR処理 */ };
request.onsuccess = function(event) {
try {
objectStore = db.createObjectStore("mydata", { keyPath: "name" });
objectStore.createIndex("name", "name", { unique: true });
}catch(e){}
};
}
function addData(){
if (!db) return;
var nstr = document.getElementById("name").value;
var estr = document.getElementById("email").value;
var tstr = document.getElementById("tel").value;
var data = { name: nstr, email: estr, tel:tstr };
var objectStore = db.transaction("mydata",IDBTransaction.READ_WRITE).objectStore("mydata");
objectStore.put(data);
}
</script>
</head>
<body onload="initial();">
<h1>Index DB Sample.</h1>
<input type="text" id="name"><br>
<input type="text" id="email"><br>
<input type="text" id="tel"><br>
<input type="button" value="Add" onclick="addData();">
</body>
</html>
| << 前へ | 次へ >> |