晕死,qq邮箱这边回不了,直接贴上来吧。。。0 m9 P( o+ |; T& h
//仅是新增用户名密码为例。。。。。具体新增其他东西直接修改即可,这是个js页面,
5 { a' X# g3 P, Z1 ~$(initTable);" b" S0 A# ?( D) c
var edit=false;7 i q+ {9 L' X1 R
function initTable(){
5 R! G* s7 x' X+ e* y var bodyHTML="";
/ M9 X |6 E, g) K. _& K; [ bodyHTML += createTR('0097','张三');
X: V" D5 E1 b8 i; f' L+ w bodyHTML += createTR('0098','李四');# k% X! I' h% M7 f5 d% @
bodyHTML += createTR('0099','王五');% h* v7 C- C9 }5 W7 Z, q5 l
$("#userList").html(bodyHTML);
T7 {. P: [- `) p* H7 G" ^ - P! @! B5 F( @$ @. \$ f, p
//新增1 ^' \/ v9 {0 a- t+ d& f
$("#addUser").click(function(){! b& L" }& O0 |
addUser();
7 f. c+ r/ x, e' x. M3 ^ });
2 g7 _' s( k- j9 s}" J2 {8 e2 C8 U9 O* E" ?
//创建行
8 a: n. N9 n9 l. I1 r# Xfunction createTR(userCode,userName){4 ], |' x/ i# \* p8 ^
var html = "";0 R, m4 P8 \' L4 H
html += "<tr class=\\"tdItem\\" >" / x9 |4 @" T1 g7 M' Q$ g* O
+ "<td><input type=\\"checkbox\\"/></td>" ) ?5 C1 Y1 A- S) D$ G: n
+ "<td>" + userCode + "</td>"
7 }/ \" a- q* ?; t2 K+ z1 S. Z1 a: k$ C + "<td>" + userName + "</td>"
; F9 s% X# G% F! D8 B( y' W2 L + "<td><a href=\\"javascript:void(0);\\" onclick=\\"userView(this);\\" class=\\"opLink\\">查看</a> | <a href=\\"javascript:void(0)\\" class=\\"opLink\\" onclick=\\"deleteUser(this)\\">删除</a></td>"" n1 K) R/ c* b% m) ?
return html;% h3 f/ l& M1 c* L* z
}
/ f) x% q# p& a//添加用户资料7 }: {! P, H/ `5 j
function addUser(){
: N5 Y$ E/ Y( {* \& ? $("#addUser").attr("disabled","true").addClass("icoNone");$ z0 y( T: b: Q& }. a$ `- U) [
if (edit) {
4 a% N4 M0 `0 b/ ?1 \, u alert("请先保存");5 S3 `6 T" U8 }+ U; k" v( @, G
return;
" Q; j( b: B- H } else {' L! j% G: F9 [# S4 @2 n( |
edit = true;
6 n- [: e3 P& d: X }
4 @( p- r' P) u' B, j var userList="<tr class=\\"tdItem\\">"0 A2 L5 H0 ^4 V2 V, @4 ~
+"<td> </td>"
, ?$ S+ M. X1 d6 \5 a( W# `4 s' d +"<td><input id=\\"userCode\\" type=\\"text\\" maxlength=\\"50\\" style=\\"width:90px\\"></td>"+ j2 ~% y3 }' O9 I. a/ X
+"<td><input id=\\"userName\\" type=\\"text\\" maxlength=\\"50\\" style=\\"width:90px\\"></td>"5 w' l& @* E# v7 Q
+"<td><a href=\\"javascript:void(0)\\" class=\\"opLink\\" onclick=\\"userSave(this)\\">保存</a> | <a href=\\"javascript:void(0)\\" class=\\"opLink\\" onclick=\\"cancelSave(this)\\">取消</a></td>"
0 u6 R/ I) e4 x: s" k( X +"</tr>";( T/ J+ I7 q. x0 }$ I% |0 R
+ q8 I; h3 @& n K& r; w if($("#userList tr").length==0){
0 c: g, P5 e3 x: h8 G $("#userList").append(userList)1 k1 B# e8 p2 b/ E1 ~( v+ w
}else{
o# L2 r" D9 @3 W+ }. b, l $(userList).insertBefore($("#userList tr:eq(0)"));- L7 k! J1 J7 R, [9 d# E
}
& {, }# E8 `7 s y4 V2 V: i}! o# v7 C3 p% L- B, C3 d
//保存8 \* ?! N; p* O. r
function userSave(self){4 c9 c" c8 t: x2 r/ x# `+ q0 p! v
var userCode=$("#userCode").val();: J2 w* U0 M B1 t% N% ~
var userName=$("#userName").val();1 q. J6 j2 m0 Y/ L/ z4 _( R
if(userCode==""){
9 F* u7 j+ i# [ alert("用户代码不能为空");
- r) i" `; o4 h( B G# J2 C8 P return;
8 X u* Y" G% K; w8 X }7 S. O/ [% I& F0 f' j: h
if(userName==""){
. a' I2 D! e/ Q$ i alert("用户名不能为空"); E% ~( g0 l5 |/ r- K* N
return;; _, @/ Z( |" H2 ?3 W) W
}
4 B5 ~! u$ c2 w, m1 R var userList=createTR(userCode,userName);" N: M) U, w4 y+ b. O0 ?. V
if($("#userList tr").length==0){
9 |) ^0 `+ n! s3 Y2 q' S $("#userList").append(userList)7 u; S7 s$ F+ r' x* a T2 W' w
}else{ b: A9 ^8 Q2 F2 ^
$(userList).insertBefore($("#userList tr:eq(0)"));+ Q' p$ K: F7 m; X. E
}7 \9 }) l9 J7 ^
cancelSave(self);6 Q2 J# ~7 O$ K5 t
}9 {: h6 g+ k* w5 y$ ]
//取消
& P: z6 E; a7 z \function cancelSave(self){5 i# E ^2 X8 f
edit = false;9 x9 i$ L: W. q7 E
$(self).parent().parent().remove();
- L- Z* _: V- }. ]% O" _ $("#addUser").removeAttr("disabled","true").removeClass("icoNone");8 H- ~6 s; P- e5 X Q
}
, ~, d( i" |) d: H0 O2 o2 S5 A//删除+ E3 E$ }- D9 k: X
function deleteUser(self){' S# \4 |1 z; Q; A! X- [! S
$(self).parent().parent().remove();, L0 n2 }% ]4 o+ W/ [9 \. {
) a1 b$ ?7 [" b& ]- S}$ H$ W% E* x# l2 F2 [. F
//查看用户资料& b B/ \) _$ X, I
function userView(self){% p/ M% a$ }9 G: U3 p
var selfObj=$(self).parent().parent().find("td");
3 R" o- _% h3 g2 p0 h( m& Z# D var userCode = selfObj.eq(1).text(); G7 y/ j Y2 @% e& b/ r9 ^
var userName = selfObj.eq(2).text();/ k' V% r) h! Q T: r. l
alert("用户代码:"+userCode+";"+"用户名:"+userName);
. h7 w, j" u6 S4 T" S7 z8 t* X2 T* _} |