使用 HTML5 代码,即使触发了 onsuccess 事件,我也无法从数据库中删除。我的删除代码如下:
btnDelete.addEventListener("click", function(){
//alert("At Delete function");
var AadharNumber = document.getElementById("AadharNumber").value;
var transaction = db.transaction("CustDetails",IDBTransaction.READ_WRITE);
var objectStore = transaction.objectStore("CustDetails");
var request = objectStore.delete(AadharNumber);
request.onsuccess = function(event){
alert( "Aadhar Number: "+ AadharNumber + " deleted from the database");
};
},false);
然后当我在删除后单击打印按钮时,我仍然可以看到相同的记录。下面是我的打印功能。
btnPrint.addEventListener("click", function () {
var output = document.getElementById("printOutput");
output.textContent = "";
var transaction = db.transaction("CustDetails", IDBTransaction.READ_WRITE);
var objectStore = transaction.objectStore("CustDetails");
var request = objectStore.openCursor();
request.onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
output.textContent += "<li>""Aadhar Number: " + cursor.key + " is " + cursor.value.name + "</li>";
cursor.continue();
}
else {
console.log("No more entries!");
}
};
}, false);
我的html代码如下:
<body><center>
<div id="container">
<label for="txtName">
Name:
</label>
<input type="text" id="txtName" name="txtName" />
<br />
<label for="txtEmail">
Email:
</label>
<input type="text" id="txtEmail" name="txtEmail" />
<br />
<input type="button" id="btnAdd" value="Add Record" />
<br />
<label for="AadharNumber">
ID:
</label>
<input type="text" id="AadharNumber" name="txtAadharNumber" />
<input type="button" id="btnDelete" value="Delete Record" />
<br />
<input type="button" id="btnPrint" value="Print Records" />
<br />
<output id="printOutput" > </output>
</div>
</center>
</body>
我的删除有什么问题?谢谢。