JSQL 基于客户端的成绩统计实现方法


Posted in Javascript onMay 05, 2010
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>Marks Count</title> 
<script type="text/javascript" src="../src/YESBRAIN.js"></script> 
<script type="text/javascript" src="../src/JSQL.js"></script> 
<script type="text/javascript" src="../src/JSQL-Memory.js"></script> 
<script type="text/javascript" src="../src/JSQL-DOM.js"></script> 
<style> 
#marks input { 
width: 100px; 
} 
</style> 
</head> 
<body> 
<center> 
<h1>Marks Count</h1> 
<p> 
<button onclick="insertline();"> Add one line </button> 
<button onclick="savemarks();"> Save Changes </button> 
<span>By<span> 
<select id="byfield"> 
<option value="chinese" selected="selected">Chinese</option> 
<option value="math">Math</option> 
<option value="english">English</option> 
</select> 
<select id="ascdesc"> 
<option value="desc" selected="selected">Desc</option> 
<option value="asc">Asc</option> 
</select> 
<button onclick="order();">Order</button> 
</p> 
<form name="marks" id="marks"> 
<span>Name:</span> 
<input type="text" id="name[1]" value="zhangsan"> 
<span>Sex:</span> 
<input type="text" id="sex[1]" value="female"> 
<span>Chinese:</span> 
<input type="text" id="chinese[1]" value="96"> 
<span>Math:</span> 
<input type="text" id="math[1]" value="94"> 
<span>English:</span> 
<input type="text" id="english[1]" value="98"> 
<br> 
</form> 
</center> 
<script type="text/javascript"> 
var marks = [ 
{ 
name: 'Lisi', 
sex: 'Female', 
chinese: '88', 
math: '90', 
english: '92' 
}, 
{ 
name: 'Wangwu', 
sex: 'Female', 
chinese: '92', 
math: '80', 
english: '82' 
}, 
{ 
name: 'Lilei', 
sex: 'Female', 
chinese: '93', 
math: '88', 
english: '87' 
}, 
{ 
name: 'HanMeimei', 
sex: 'Male', 
chinese: '97', 
math: '92', 
english: '100' 
}, 
{ 
name: 'Wangjuan', 
sex: 'Male', 
chinese: '92', 
math: '93', 
english: '90' 
} 
]; function addto(index,name,sex,chinese,math,english) { 
"insert into marks (nodename,innerHTML) values ('span','Name:')".ForDOM().execute(); 
("insert into marks (nodename,type,id,value) values ('input','text','name[" + (index) + "]','" + name + "')").ForDOM().execute(); 
"insert into marks (nodename,innerHTML) values ('span','Sex:')".ForDOM().execute(); 
("insert into marks (nodename,type,id,value) values ('input','text','sex[" + (index) + "]','" + sex + "')").ForDOM().execute(); 
"insert into marks (nodename,innerHTML) values ('span','Chinese:')".ForDOM().execute(); 
("insert into marks (nodename,type,id,value) values ('input','text','chinese[" + (index) + "]','" + chinese + "')").ForDOM().execute(); 
"insert into marks (nodename,innerHTML) values ('span','Math:')".ForDOM().execute(); 
("insert into marks (nodename,type,id,value) values ('input','text','math[" + (index) + "]','" + math + "')").ForDOM().execute(); 
"insert into marks (nodename,innerHTML) values ('span','English:')".ForDOM().execute(); 
("insert into marks (nodename,type,id,value) values ('input','text','english[" + (index) + "]','" + english + "')").ForDOM().execute(); 
("insert into marks (nodename) values ('br')").ForDOM().execute(); 
}; 
for(var i=0; i<marks.length;i++) { 
addto(i+2,marks[i].name,marks[i].sex,marks[i].chinese,marks[i].math,marks[i].english); 
}; 
function insertline() { 
var count = "select count(*) as Count from marks where id like 'name%'".ForDOM().query(); 
var index = count[0].Count + 1; 
addto(index,"","","","",""); 
}; 
function dellastline() { 
var count = "select count(*) as Count from marks where id like 'name%'".ForDOM().query(); 
var index = count[0].Count; 
("delete from marks where id like '%["+ index +"]'").ForDOM().execute(); 
}; 
"create table savedmarks".execute(); 
function savemarks() { 
var names = ("select value from marks where id like 'name%'").ForDOM().query(); 
var sexs = ("select value from marks where id like 'sex%'").ForDOM().query(); 
var chineses = ("select value from marks where id like 'chinese%'").ForDOM().query(); 
var maths = ("select value from marks where id like 'math%'").ForDOM().query(); 
var englishs = ("select value from marks where id like 'english%'").ForDOM().query(); 
"delete from savedmarks".execute(); 
for(var i=0;i<names.length;i++) { 
("insert into savedmarks (name,sex,chinese,math,english) values ('"+ names[i].value +"','" + sexs[i].value + "'," + chineses[i].value + "," + maths[i].value + "," + englishs[i].value + ")").execute(); 
}; 
//alert(savedmarks); 
}; 
function orderby(field,asc) { 
savemarks(); 
var marks = ("select * from savedmarks order by " + field + " " + asc).query(); 
"delete from marks".ForDOM().execute(); 
for(var i=0; i<marks.length;i++) { 
addto(i+2,marks[i].name,marks[i].sex,marks[i].chinese,marks[i].math,marks[i].english); 
}; 
}; 
function order() { 
var byfield = document.getElementById("byfield").value; 
var ascdesc = document.getElementById("ascdesc").value; 
orderby(byfield,ascdesc); 
}; 
</script> 
</body> 
</html>

主要用到四个JS库,其中YESBRAIN.js是基库,JSQL.js是接口。JSQL-Memory.js和JSQL-DOM分别是JSQL对 javascript Objects Array 和 Html DOM 的 SQL 实现。

jsql javascript

Javascript 相关文章推荐
innerHTML,outerHTML,innerTEXT三者之间的区别
Jan 28 Javascript
jquery对dom的操作常用方法整理
Jun 25 Javascript
JavaScript运行时库属性一览表
Mar 14 Javascript
JS去除iframe滚动条的方法
Apr 01 Javascript
js实现延迟加载的方法
Jun 24 Javascript
Bootstrap3 多选和单选框(checkbox)
Dec 29 Javascript
原生js实现密码输入框值的显示隐藏
Jul 17 Javascript
说说AngularJS中的$parse和$eval的用法
Sep 14 Javascript
CentOS环境中MySQL修改root密码方法
Jan 07 Javascript
vue项目持久化存储数据的实现代码
Oct 01 Javascript
vue 中 beforeRouteEnter 死循环的问题
Apr 23 Javascript
js实现九宫格布局效果
May 28 Javascript
JSQL SQLProxy 的 php 版本代码
May 05 #Javascript
JSQL  一个 web DB 的封装
May 05 #Javascript
Javascript JSQL,SQL无处不在,
May 05 #Javascript
Javascript 去除数组的重复元素
May 04 #Javascript
JavaScript中SQL语句的应用实现
May 04 #Javascript
javascript 文章截取部分无损html显示实现代码
May 04 #Javascript
跨浏览器的 mouseenter mouseleave 以及 compareDocumentPosition的使用说明
May 04 #Javascript
You might like
typecho插件编写教程(二):写一个新插件
2015/05/28 PHP
php调用淘宝开放API实现根据卖家昵称获取卖家店铺ID的方法
2015/07/29 PHP
php防止CC攻击代码 php防止网页频繁刷新
2015/12/21 PHP
PHP中mysqli_get_server_version()的实例用法
2020/02/03 PHP
新浪刚打开页面出来的全屏广告代码
2007/04/02 Javascript
JavaScript学习点滴 call、apply的区别
2010/10/22 Javascript
js弹出的对话窗口永远保持居中显示
2012/12/15 Javascript
JavaScript实现彩虹文字效果的方法
2015/04/16 Javascript
jquery+html5烂漫爱心表白动画代码分享
2015/08/24 Javascript
基于PHP和Mysql相结合使用jqGrid读取数据并显示
2015/12/02 Javascript
Bootstrap源码解读导航(6)
2016/12/23 Javascript
ES6深入理解之“let”能替代”var“吗?
2017/06/28 Javascript
Angular4开发解决跨域问题详解
2017/08/28 Javascript
iView-admin 动态路由问题的解决方法
2018/10/03 Javascript
Vue项目中使用better-scroll实现一个轮播图自动播放功能
2018/12/03 Javascript
JS原型与继承操作示例
2019/05/09 Javascript
node中IO以及定时器优先级详解
2019/05/10 Javascript
webpack4 SplitChunks实现代码分隔详解
2019/05/23 Javascript
Taro UI框架开发小程序实现左滑喜欢右滑不喜欢效果的示例代码
2020/05/18 Javascript
[01:07:19]DOTA2-DPC中国联赛 正赛 CDEC vs XG BO3 第一场 1月19日
2021/03/11 DOTA
Python基于回溯法子集树模板解决最佳作业调度问题示例
2017/09/08 Python
Pycharm 操作Django Model的简单运用方法
2018/05/23 Python
对python打乱数据集中X,y标签对的方法详解
2018/12/14 Python
python selenium执行所有测试用例并生成报告的方法
2019/02/13 Python
PyTorch中Tensor的拼接与拆分的实现
2019/08/18 Python
python中使用paramiko模块并实现远程连接服务器执行上传下载功能
2020/02/29 Python
django和flask哪个值得研究学习
2020/07/31 Python
pycharm 2020.2.4 pip install Flask 报错 Error:Non-zero exit code的问题
2020/12/04 Python
python 利用openpyxl读取Excel表格中指定的行或列教程
2021/02/06 Python
python实现图片转字符画的完整代码
2021/02/21 Python
英国珠宝钟表和家居礼品精品店:David Shuttle
2018/02/24 全球购物
中国跨境在线时尚零售商:Bellelily
2018/04/06 全球购物
2014庆六一活动方案
2014/03/02 职场文书
幼儿园感谢信
2015/01/21 职场文书
2016新年问候语大全
2015/11/11 职场文书
关于ObjectUtils.isEmpty() 和 null 的区别
2022/02/28 Java/Android