效果:
代码:
StringUtil.js
//去除字符串中间空格
String.prototype.Trim = function() {
return this.replace(/(^s*)|(s*$)/g, "");
}
//去除字符串左侧空格
String.prototype.LTrim = function() {
return this.replace(/(^s*)/g, "");
}
//去除字符串右侧空格
String.prototype.RTrim = function() {
return this.replace(/(s*$)/g, "");
}
//去除字符串中所有空格(包括中间空格,需要设置第2个参数为:g)
function Trim(str,is_global){
var result;
result = str.replace(/(^s+)|(s+$)/g,"");
if(is_global.toLowerCase()=="g")
result = result.replace(/s/g,"");
return result;
}
indexedDB.js
window.onload = function(){
if(!window.indexedDB){
window.indexedDB = window.mozIndexedDB || window.webkitIndexedDB;
}
var db = null;
var request = indexedDB.open("mydb");
request.onupgradeneeded = function(e){
//db = request.result;
db = e.target.result;
createObjectStore(db);
}
function createObjectStore(db){
if(db.objectStoreNames.contains("customer")){
db.deleteObjectStore("customer");
}
var objectStore = db.createObjectStore("customer",{keyPath:"id",autoIncrement:true});
objectStore.createIndex("name","name",{unique:false});
objectStore.createIndex("email","email",{unique:true});
objectStore.add({name: "Tom", sex: "male", age: 34, email: "tom@facebok.org"});
objectStore.add({name: "Jiny", sex: "female", age: 25, email: "jiny@home.org"});
objectStore.add({name: "Liam", sex: "male", age: 23, email: "liam@163.com"});
}
request.onsuccess = function(e){
db = e.target.result;
if(!db.version=="1.0"){
var request = db.setVersion("1.0");
request.onsuccess = function(e){
createObjectStore(db);
showDataByCursor();
}
request.onerror = function(e){
alert(e);
}
}else{
showDataByCursor();
}
}
function showDataByCursor(objectStore){
if(!objectStore){
var transaction = db.transaction(["customer"]);
objectStore = transaction.objectStore("customer");
}
console.log("Store-Name : "+objectStore.name);
console.log("Store-KeyPath : "+objectStore.keyPath);
var request = objectS