js客戶端數據庫的對象與函數
2024-07-21 02:14:22
供稿:網友
有時候想在網頁上使用客戶端數據庫,但為了兼容第版本的瀏覽器不支持xml技術,所以在此編了一些js的dml函數希望有興趣的朋友一起討論
function trform()
{
this.trrc=new array();
this.qrc=new array();//結果
this.currentrc=1;//當前紀錄指針
this.lastrc=0;//最后紀錄
this.rclength=arguments.length;//字段數
this.trrc[0]=new array();//字段名
for(i=0;i<this.rclength;i++) this.trrc[0][i]=arguments[i];
this.addrc=addrc; //加一條紀錄
this.showrc=showrc;//打印當前紀錄
this.showprevious=showprevious;
this.shownext=shownext;
this.preload=preload; //預裝載圖像
this.item2index=item2index;//使字段名到數組的索引
this.showthis=showthis;
this.isright=isright;
this.seek=seek;
}
function addrc()
{
this.trrc[++this.lastrc]=new array();
for(i=0;i<this.rclength;i++) this.trrc[this.lastrc][i]=arguments[i];
return true;
}
function showrc(){
for(rc=0;rc<this.qrc[0].length;rc++)
{
theel=eval(this.qrc[0][rc]);
if(this.qrc[0][rc].indexof("image")==-1){
theel.innertext=this.qrc[this.currentrc][rc]
}
else{
theel.src=this.qrc[this.currentrc][rc];
}
}
return true;
}
function shownext(){
this.seek("all","all")
if(++this.currentrc>this.lastrc) this.currentrc=this.lastrc;
this.showrc();
}
function showthis(){
this.seek("all","all")
this.showrc();
}
function showprevious(){
this.seek("all","all");
if(--this.currentrc==0) this.currentrc=1;
this.showrc();
}
function preload(){
if(confirm('您需要先將圖片載入內存嗎,這樣可以提高瀏覽時的平滑度.如果您的網絡速度較慢的話,建議不要載入','明暗界限')){
status='圖片裝入中';
var imageindex=new array();
var n=0;
for(i=0;i<this.rclength;i++){
if(this.trrc[0][i].indexof("image")!=-1) imageindex[n++]=i;
}
for (i=1;i<=this.lastrc;i++){
for(var ii in imageindex){
var preimage=new image();
preimage.src=this.trrc[i][ii];
status+='.'
}
}
}
status='';
return true;
}
function item2index(item)
{
val=-1
for(i=0;i<this.rclength;i++)
if(this.trrc[0][i]==item) val=i;
return val;
}
function isright(rc,item,oper,exp)
{
id=this.item2index(item);
ends=false;
if(eval("this.trrc[rc][id]"+oper+"exp")) ends=true;
return ends;
}
function seek(exp1,item1)
{
var getexp=exp1.split("@");
this.qrc=new array();
var n=0;
var showitems=new array();
if(item1=='all') for(i=0;i<this.trrc[0].length;i++) showitems[i]=this.trrc[0][i];
else{
for(i=1;i<arguments.length;i++)
showitems[n++]=arguments[i];
}
this.qrc[0]=new array();
for(m=0;m<showitems.length;m++)
{
this.qrc[0][m]=showitems[m];
}
for(m=0;m<showitems.length;m++)
{
showitems[m]=this.item2index(showitems[m]);
}
temp=1;
if(getexp[0]=='all'){
for(k=1;k<=this.lastrc;k++)
{
this.qrc[temp++]=new array();
for(i=0;i<showitems.length;i++)
{
this.qrc[temp-1][i]=this.trrc[k][showitems[i]];
}
}
}
else
{
for(k=1;k<=this.lastrc;k++)
{
if(this.isright(k,getexp[0],getexp[1],getexp[2]))
{
this.qrc[temp++]=new array();
for(i=0;i<showitems.length;i++)
{
this.qrc[temp-1][i]=this.trrc[k][showitems[i]];
}
}
}
}
return this.qrc;
}