晕死,qq邮箱这边回不了,直接贴上来吧。。。: w& }4 z- {) w6 C% H; Q
//仅是新增用户名密码为例。。。。。具体新增其他东西直接修改即可,这是个js页面,2 ?# S4 ~" n- t7 h0 m
$(initTable);
) Y b2 S1 U( P" cvar edit=false;
1 B. f0 h' {4 w& sfunction initTable(){
# |6 }) q7 b9 _. K' g var bodyHTML="";4 K2 H9 R, Y! p7 \
bodyHTML += createTR('0097','张三');" v Z3 N+ i& F4 n, T# H
bodyHTML += createTR('0098','李四');
! A* [6 n% s6 @0 l' | bodyHTML += createTR('0099','王五');
8 j0 M5 U( E. } b& p $("#userList").html(bodyHTML);
/ y$ a7 b9 e% V/ }
! Z: z+ F6 A" D, i1 R5 K7 t //新增9 v) N$ A' O3 T
$("#addUser").click(function(){- I) ^, H: T* _ I) Z
addUser();8 K1 e r/ S: D2 N4 ^+ y/ T
});8 ~% o; X/ \: ]
}
d* p' x) \6 {. ^3 w* t) e6 [* u! {//创建行
/ n- y' I j' D& B7 Pfunction createTR(userCode,userName){
$ e. J/ V! R# o! p var html = "";
' E' p0 |7 e% ? html += "<tr class=\\"tdItem\\" >"
0 x) n; c0 d) h, H + "<td><input type=\\"checkbox\\"/></td>"
5 B3 Y% N8 ]4 b, t& p; e + "<td>" + userCode + "</td>" * Z+ V/ l& Z/ I2 _9 I6 i
+ "<td>" + userName + "</td>" # J7 m, ^) h7 d% i8 y( Z# G8 j3 ^
+ "<td><a href=\\"javascript:void(0);\\" onclick=\\"userView(this);\\" class=\\"opLink\\">查看</a> | <a href=\\"javascript:void(0)\\" class=\\"opLink\\" onclick=\\"deleteUser(this)\\">删除</a></td>"
$ d; v, ~, U3 ] return html;
2 x0 q% E$ b) d+ y/ P3 H}
* H3 ?. T$ @; ~7 ]' \$ ~. S//添加用户资料
4 l$ U0 h. Z7 s7 g& n: j% e! tfunction addUser(){& P: j4 D$ p' z* }+ r% l7 B
$("#addUser").attr("disabled","true").addClass("icoNone");' p5 Y0 b& J/ @5 J) a0 S5 B
if (edit) {) K9 |4 f& D7 Z0 \& y! O- o1 s
alert("请先保存");, Z! ~7 h" j3 s- D
return;( F+ {4 O2 K. R) ^
} else {
. G& d; w+ X" K f* J& g" a ] edit = true;
2 u2 a( t | K% E& Q }) n! T: u8 k2 P: o6 F) V% _
var userList="<tr class=\\"tdItem\\">"
9 x8 `! w* {( Q+ O) Q5 n9 t; @ +"<td> </td>"
! f1 F. Z& [; {9 u +"<td><input id=\\"userCode\\" type=\\"text\\" maxlength=\\"50\\" style=\\"width:90px\\"></td>"& A8 [+ i, A* c/ x/ S& k; _
+"<td><input id=\\"userName\\" type=\\"text\\" maxlength=\\"50\\" style=\\"width:90px\\"></td>"7 o7 p* y2 U. ~( p
+"<td><a href=\\"javascript:void(0)\\" class=\\"opLink\\" onclick=\\"userSave(this)\\">保存</a> | <a href=\\"javascript:void(0)\\" class=\\"opLink\\" onclick=\\"cancelSave(this)\\">取消</a></td>" |) P' W7 w* _5 w+ U6 v! @
+"</tr>";
8 E H& }8 y) l4 @: {4 O( }. ? " F% a3 a! A/ c% N
if($("#userList tr").length==0){
& ^ K/ r" L8 l& f5 _ $("#userList").append(userList)
* N, u& a1 o3 f. E$ ` }else{6 z& u; t+ Y& g$ F, i8 C" b
$(userList).insertBefore($("#userList tr:eq(0)"));
3 U0 Y5 M) y7 C- H B) m }
* ^$ o% J& _: V+ @}' c, G7 F+ c9 |# u% Y0 K p
//保存) N3 |. G5 D6 a9 {( `# p$ B
function userSave(self){
, C/ i) ~9 T" s% F3 e8 P var userCode=$("#userCode").val();
% Y: R. ?, h+ U* o: L var userName=$("#userName").val();. l% x5 D, N s# j: Q* x/ S
if(userCode==""){; A; K/ R* o" D$ a/ s
alert("用户代码不能为空");
4 h* O4 {8 N' g: f. s return;9 {7 G4 H" d6 K5 L) s& g. c
}/ |0 w* C9 ~0 C$ v+ q: X( D# i/ \
if(userName==""){
3 @9 K/ _1 e/ Q$ s- ? alert("用户名不能为空");
7 c' t- e- D6 M% n return;
, K; O# R3 k% { }2 S/ t. ~5 |4 @% g
var userList=createTR(userCode,userName);
, T% L2 j: g* f1 Z5 y# d7 F if($("#userList tr").length==0){
% f! C" a. n1 T0 W $("#userList").append(userList)
0 U$ n# Q# H4 U& n n8 `9 }9 e7 ` }else{
& I) J1 K! r2 X2 R- } $(userList).insertBefore($("#userList tr:eq(0)"));
' y$ I5 l/ y6 I5 T$ }- P3 T }% v+ R$ r4 X) r8 g2 D; e; p
cancelSave(self);+ y/ T, R* U! l) e
}
6 x+ P% V& z1 H6 e1 s1 F- t+ B3 Y//取消
: F3 i" f3 |1 h. |, Afunction cancelSave(self){
: Y& }6 R0 O$ h; f edit = false;
/ [+ L- x7 K0 y# h4 \ $(self).parent().parent().remove(); N0 B. b4 A' d+ J' |$ ~) L& Y* F0 z
$("#addUser").removeAttr("disabled","true").removeClass("icoNone");
$ L: W; l, e! H6 E}
% {" H1 P* G* d9 V//删除; n; T3 F q% i/ s
function deleteUser(self){ ^9 w7 }. r" k( O
$(self).parent().parent().remove();
7 [5 @! @& \2 s0 o9 \ - _$ \5 v$ z3 Q+ p% U
}( o$ b3 A4 n; N4 B) X
//查看用户资料
$ K7 P2 {- j6 D. ufunction userView(self){
X% V& l5 M( `; U6 z p5 `: p var selfObj=$(self).parent().parent().find("td");
5 j! S/ ?# s8 o var userCode = selfObj.eq(1).text();
; l7 K' U3 e0 _. O var userName = selfObj.eq(2).text();
# ^+ y2 ]3 n& p9 N" g alert("用户代码:"+userCode+";"+"用户名:"+userName);
- G" V8 Q/ o% a0 M( V, a} |