SQL语句在JavaScript中的应用(2)
var result = SQL.executeSQL();
for(var i=0; i<result.length; i++) {
//do something here.... using result[i];
};
"create table mytable".executeSQL();
for(var j=0; j<100; j++) {
"insert into mytable (id,name,sex) values(2,'zhangsan',true) ".executeSQL();
};
操作Object Array
其实还可以这样操作:
var Room = [
{
ID: 'bot',
name: 'test',
sex: true
}, {
ID: 2,
name: 'test8',
sex: true
}, {
ID: 3,
name: 'test5',
sex: false
}, {
ID: 4,
name: 'test2',
sex: true
}];
"update Room set name = 'man' where sex=true".executeSQL();
支持的SQL语句有 SELECT \ INSERT \ UPDATE \ DELETE \ CREATE TABLE \ DROP TABLE
3.上回说道我发现DOM其实也可以用SQL操作
比方说,你可以直接插入100个图片element操作如下:
'create table logolist'.ForDOM().executeSQL();
for(var i=0;i<100;i++) {
"insert into logolist(nodename,title,src) values ('img','google','images/google.gif')".ForDOM().execute();
};
或者是DELETE这些符合条件的元素:
("delete from logolist where title='google'").ForDOM().execute();
亦或是充当selector:
var result = ("select * from logolist").ForDOM().execute();
for(var i=0;i<result.length;i++) {
result[i].src = 'baidu.gif';
};
- 最新评论