Home > Web Front-end > JS Tutorial > Javascript method to implement information addition, deletion, modification and query_javascript skills

Javascript method to implement information addition, deletion, modification and query_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:49:07
Original
1255 people have browsed it

The example in this article describes the method of adding, deleting, modifying and checking information using JavaScript. Share it with everyone for your reference. The specific implementation method is as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

<body>

<div align="center">

 <h1>显示所有的用户界面</h1>

 <div style="border: 1px red solid; margin-bottom: 100px; padding: 10px 10%;">

 <table border="1px" cellpadding="0" cellspacing="0" id="tusers">

 <thead>

 <tr><th><input type="checkbox" name="chbk" id="chbk1" onclick="selectAll()"/></th>

 <th>名称</th>

  <th>性别</th>

  <th>邮箱</th>

   <th>出生日期</th>

   <th>操作</th>

 </tr>

 </thead>

 <tbody id="users">

 </tbody>

 </table>

 <div id="pages"></div>

 </div>

 <div style="border: 1px blue solid;">

  <form action="">

  <table id="divs">

  <tbody id="addUsers">

  <tr>

  <td>用户名:</td>

  <td><input type="text" name="name" id="name"/></td>

  </tr>

  <tr>

  <td>性别:</td>

  <td><select id="sex">

  <option value="男">男</option>

  <option value="女">女</option>

  </select>

  </td>

  </tr>

  <tr>

  <td>邮箱</td>

  <td><input type="text" name="email" id="email"/></td>

  </tr>

  <tr>

  <td>出生日期:</td>

  <td>

  <input type="text" id="bir" name="bir"/>

  <input type=button value="添加日期" onclick="showCalender(this,document.all.bir)"/>

  </td>

  </tr>

  <tr id="addu">

  <td colspan="2"><input type="button" value="添加" onclick="addUser()" id="add"/></td>

  </tr>

  <tr id="addu1">

  <td colspan="2"><input type="button" value="修改" id="upduser" /></td>

  </tr>

  </tbody>

  </table>

  </form>

 </div>

</div>

</body>

<script>

window.onload = function(){

alert("onload");

document.getElementById("addu1").style.display = "none";

}

function selectAll(){

var users = document.getElementById("users");

var ips = users.getElementsByTagName("input");

var chbk = document.getElementById("chbk1");

for(var i=0;i<ips.length;i++){

ips[i].setAttribute("checked",chbk.getAttribute("checked"));

}

}

function addUser(){

alert("add");

var name = document.getElementById("name").Value;

var sex = document.getElementById("sex").Value;

var email = document.getElementById("email").Value;

var bir = document.getElementById("bir").Value;

var tusers = document.getElementById("tusers").Value;

var tr1 = document.createElement("tr");

var cbk = document.createElement("td");

var tname = document.createElement("td");

var tsex = document.createElement("td");

var temail = document.createElement("td");

var tbir = document.createElement("td");

var toper = document.createElement("td");

var cbk1 = document.createElement("input");

cbk1.setAttribute("type","checkbox");

cbk1.setAttribute("name","chbk");

cbk.appendChild(cbk1);

tname.appendChild(document.createTextNode(name));

tsex.appendChild(document.createTextNode(sex));

temail.appendChild(document.createTextNode(email));

tbir.appendChild(document.createTextNode(bir));

var adelete = document.createElement("a");

var aupdate = document.createElement("a");

adelete.setAttribute("href","#");

aupdate.setAttribute("href","#");

adelete.appendChild(document.createTextNode("删除|"));

aupdate.appendChild(document.createTextNode("修改"));

toper.appendChild(adelete);

toper.appendChild(aupdate);

tr1.appendChild(cbk);

tr1.appendChild(tname);

tr1.appendChild(tsex);

tr1.appendChild(temail);

tr1.appendChild(tbir);

tr1.appendChild(toper);

var users = document.getElementById("users");

users.appendChild(tr1);

tusers.appendChild(users);

adelete.onclick = function(){

users.removeChild(adelete.parentNode.parentNode);

}

aupdate.onclick function(){

document.getElementById(addu).style.display = "none";

document.getElementById(addu1).style.display = "block";

var utr = aupdate.parentNode.parentNode;

var utrs = utr.childNodes;

document.getElementById("name").value = utrs[1].innerHTML;

document.getElementById("sex").value = utrs[2].innerHTML;

document.getElementById("email").value = utrs[3].innerHTML;

document.getElementById("bir").value = utrs[4].innerHTML;

var upUser = document.getElementById("upduser");

upUser.onclick = function(){

utr.childNodes[1].innerHTML = document.getElementById("name").value;

utr.childNodes[2].innerHTML = document.getElementById("sex").value;

utr.childNodes[3].innerHTML = document.getElementById("email").value;

utr.childNodes[4].innerHTML = document.getElementById("bir").value;

document.getElementById("addu1").style.display = "none";

document.getElementById("addu").style.display = "block";

}

}

testPage()

}

var indexPage = document.createElement("a");

var upPage = document.createElement("a");

var downPage = document.createElement("a");

var endPage = document.createElement("a");

var nowpage = 1;

function testPage(){

var tbodyUsers = document.getElementById("users");

var trUsers = document.getElementById("tr");

var countRecord = trUsers.length;

var PAGESIZE = 2;

var countPage = (countRecord%PAGESIZE ==0&#63;countRecord/PAGESIZE:Math.ceil(countRecord/PAGESIZE));

var pages=document.getElementById("pages");

if(!pages.hasChildNodes()){

getPages(nowpage);

}

index.onclik=function(){

noepage=1;

indexPageInfo(countRecord,trUsers);

}

upPage.onclick=function(){

if(nowpage-1>1){

nowpage-=1;

}else{

nowpage=1;

indexPageInfo(countRecord,trUsers);

}

var startindex =(nowpage-1)*PAGESIZE;

var endindex=startindex+PAGESIZE;

PageInfo(startindex,endindex,countRecord,trUsers);

}

downPage.onclick=function(){

if(nowpage+1>=countPage){

nowpage=countPage;

}else{

nowpage=+1;

}

var startindex =(nowpage-1)*PAGESIZE;

var endindex=startindex+PAGESIZE;

PageInfo(startindex,endindex,countRecord,trUsers);

}

endPage.onclick=function(){

if(nowpage>1){

var startindex =(nowpage-1)*PAGESIZE;

for(var i=0;i<countRecord;i++){

if(i<startindex){

trUsers[i].style.display="none";

}else{

trUsers[i].style.display="block";

}

}

}else{

indexPageInfo(countRecord,trUsers);

}

}

}

function indexPageInfo(countRecord, trUsers) {

if (countRecord <= 2) {

for ( var i = 0; i < PAGESIZE; i++) {

trUsers[i].style.display = "block";

}

} else {

for ( var i = 2; i < countRecord; i++) {

trUsers[i].style.display = "none";

}

}

}

function PageInfo(startindex, endindex, countRecord, trUsers) {

for ( var i = 0; i < countRecord; i++) {

if (i >= startindex && i < endindex) {

trUsers[i].style.display = "block";

} else {

trUsers[i].style.display = "none";

}

}

}

function getPages(numpage) {

indexPage.appendChild(document.createTextNode("首页"));

indexPage.setAttribute("href", "#");

upPage.appendChild(document.createTextNode("上一页"));

upPage.setAttribute("href", "#");

downPage.appendChild(document.createTextNode("下一页"));

downPage.setAttribute("href", "#");

endPage.appendChild(document.createTextNode("末页"));

endPage.setAttribute("href", "#");

var pages = document.getElementById("pages");

pages.appendChild(indexPage);

pages.appendChild(upPage);

pages.appendChild(downPage);

pages.appendChild(endPage);

}

</script>

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template