-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeEdit.php
More file actions
95 lines (94 loc) · 3.79 KB
/
codeEdit.php
File metadata and controls
95 lines (94 loc) · 3.79 KB
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
<?php
if (isset($_POST['submit'])) {
$pageList = array();
for ($i = 0; $i < count($_POST['href']); $i++) {
$pageList[] = array(
'href' => $_POST['href'][$i],
'name' => $_POST['name'][$i],
'description' => $_POST['description'][$i],
);
}
file_put_contents('config.php', "<?php\r\n \$pageList=" . var_export($pageList, TRUE) . ';');
header('Location:index.php');
exit();
}
include 'config.php';
if (!isset($pageList) || !is_array($pageList) || empty($pageList)) {
$pageList = array();
}
?>
<!doctype html>
<html>
<head>
<title>PHP代码段</title>
<meta charset="utf-8" />
<script type="text/javascript" src="./js/jquery-1.9.0.min.js"></script>
<style type="text/css">
table{
table-layout:fixed;
empty-cells:show;
border-collapse: collapse;
margin:0 auto;
text-align: center;
}
td{
height:30px;
}
.table{
border:1px solid #cad9ea;
color:#666;
}
.table th {
background-repeat:repeat-x;
height:30px;
}
.table td,.table th{
border:1px solid #cad9ea;
padding:0 1em 0;
}
.table tr.alter{
background-color:#f5fafe;
}
a{
cursor: pointer;
}
</style>
</head>
<body>
<div style="text-align:center;"><h1>PHP代码段</h1></div>
<form action="" name="form" method="post" >
<table class="table" width="90%">
<thead>
<th width="20%">链接地址</th>
<th width="20%">标题</th>
<th width="50%">描述</th>
<th width="10%"><a onclick="addTd($(this));" number='<?php echo count($pageList); ?>'>新增</a></th>
</thead>
<tbody>
<?php foreach ($pageList as $key => $page): ?>
<tr>
<td><input type="text" value="<?php echo $page['href']; ?>" name="href[<?php echo $key; ?>]" style="width: 95%;"/></td>
<td><input type="text" value="<?php echo $page['name']; ?>" name="name[<?php echo $key; ?>]" style="width: 95%;"/></td>
<td><input type="text" value="<?php echo $page['description']; ?>" name="description[<?php echo $key; ?>]" style="width: 95%;"/></td>
<td><a onclick="delTd($(this));">删除</a></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<td colspan='4'><input type="submit" name="submit" value="保存"/><input type="button" name="cancel" value="取消" onclick="window.location.href = 'index.php';"/></td>
</tfoot>
</table>
</form>
<script>
var addTd = function (obj) {
var num = parseInt(obj.attr('number'));
var trHtml = '<tr><td><input type="text" value="" name="href[' + num + ']" style="width: 95%;"/></td><td><input type="text" value="" name="name[' + num + ']" style="width: 95%;"/></td><td><input type="text" value="" name="description[' + num + ']" style="width: 95%;"/></td><td><a onclick="delTd($(this));">删除</a></td></tr>';
$('table.table tbody').append(trHtml);
obj.attr('number', num + 1);
}
var delTd = function (obj) {
obj.parents('tr').remove();
}
</script>
</body>
</html>