学生信息管理系统之javascript版文档格式.docx
《学生信息管理系统之javascript版文档格式.docx》由会员分享,可在线阅读,更多相关《学生信息管理系统之javascript版文档格式.docx(8页珍藏版)》请在冰点文库上搜索。
for(vari=0;
i<
_data.length;
i++){
if(_data[i].id==id){
return_data[i];
}
}
returnnull;
//学生对象
functionStudent(name,sex,age,score){
this.id=newDate().getTime();
this.name=name?
name:
null;
this.age=age?
age:
0;
this.sex=sex?
sex:
'
0'
;
this.score=score?
score:
//增加方法
functionaddHandler(){
varstu=newStudent();
stu.name=$('
nName'
).value.trim();
stu.age=$('
nAge'
stu.score=$('
nScore'
stu.sex=$('
nSex'
if(valid(stu)){
_data.push(stu);
$('
resetButton'
).click();
showData(_data);
//验证输入是否正确
functionvalid(student){
if(student.name=='
'
){
alert('
用户名不能为空!
returnfalse;
if(student.age!
='
if(numReg.test(student.age)){
vartemp=parseInt(student.age,10);
if(temp<
0||temp>
200){
alert('
年龄输入错误!
returnfalse;
}
}else{
alert('
年龄请输入数字!
returnfalse;
if(student.score!
if(numReg.test(student.score)){
vartemp=parseInt(student.score);
if(temp<
100){
alert("
成绩输入错误!
returntrue;
//删除方法
functiondelHandler(id){
if(confirm('
真的要删除吗?
)){
vartemp=[];
for(vari=0;
if(_data[i].id!
=id){
temp.push(_data[i]);
_data=temp;
showData(_data);
//查询方法
functionsearch(name,sex,age){
//console.log(arguments);
vartemp=[];
if("
!
=name){
if(_data[i].name!
continue;
=sex){
if(_data[i].sex!
=age){
if(_data[i].age!
temp.push(_data[i]);
showData(temp);
//根据数据显示内容(html代码生成)
functionshowData(data){
info_body=info_body||$('
info-body'
varhtml=[];
data.length;
html.push('
tr>
td>
+data[i].name+'
/td>
+showSex(data[i].sex)+'
+data[i].age+'
+data[i].score+'
buttonclass="
btn"
style="
margin-right:
10px;
onclick="
editHandler(this,\'
+data[i].id+'
\'
)"
编辑<
/button>
btnbtn-danger"
delHandler(\'
删除<
/tr>
//此处IE低版本不兼容(促进网络进步,请升级低版本IE吧),因为IE下tbody标签的innerHTML为只读属性,要兼容请将上面代码的标签用document.createElement('
进行创建,td的innerHTML是可以进行操作的
info_body.innerHTML=html.join("
functionshowSex(v){
if(v){
if('
==v){
return'
男'
}elseif('
1'
女'
return'
error'
functioncreateSexTag(v){
if('
return'
optionvalue="
0"
男<
/option>
1"
女<
}else{
//保存修改内容
functionsaveEidted(id){
eName'
).value;
eAge'
eScore'
eSex'
if(_data[i].id==id){
_data[i]=stu;
showData(_data);
break;
//编辑
functioneditHandler(obj,id){
varpp=obj.parentNode.parentNode;
vartds=pp.getElementsByTagName('
td'
vartemp=getStudentById(id);
if(null!
=temp){
tds.length;
if(0==i){
tds[i].innerHTML='
inputid="
eName"
width:
80px"
text"
value="
+temp.name+'
if(1==i){
selectid="
eSex"
60px;
+createSexTag(temp.sex)+'
/select>
if(2==i){
eAge"
70px"
+temp.age+'
if(3==i){
eScore"
value="
+temp.score+'
if(4==i){
saveEidted(\'
+id+'
保存<
<
showData(_data)"
取消<
}
error!
/script>
styletype="
*{padding:
margin:
}
.stitle{padding-left:
20px;
text-align:
right;
.sinput{width:
100px;
border:
1px#eeesolid;
margin-top:
10px;
.sslect{width:
.ninput{position:
relative;
float:
left;
left:
-5px;
100%;
1pxsolid#eee;
/style>
/head>
body>
divstyle="
position:
fixed;
100%;
background:
#eee;
z-index:
9999;
height:
100px;
overflow:
hidden;
<
table>
<
<
tdclass="
stitle"
姓名:
inputtype="
class="
sinput"
id="
sName"
/>
50px;
性别:
<
sSex"
sslect"
<
年龄:
sAge"
&
nbsp;
button"
查询"
search($('
sName'
).value.trim(),$('
sSex'
sAge'
).value.trim())"
/table>
form>
tableclass="
table"
add-info"
tdwidth="
100"
inputclass="
ninput"
nName"
80"
nSex"
80px;
<
nAge"
nScore"
添加"
addHandler()"
reset"
resetButton"
display:
none;
/form>
/div>
absolute;
top:
bottom:
0;
auto;
right:
tabletable-borderedtable-hover"
0px;
2;
info-list"
thead>
姓名<
性别<
年龄<
成绩<
操作<
/thead>
tbodyid="
info-body"
/tbody>
/body>
/html>
--demo下载demo-->