HTML代码:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>网址收藏夹</title>
	<link rel="stylesheet" href="style.css">
</head>
<body>
	<div class="wrapper">
		<div class="header">
			<h1>网址收藏夹</h1>
			<form class="search-form">
				<input type="text" name="search" placeholder="搜索">
				<button type="submit">搜索</button>
			</form>
		</div>
		<div class="content">
			<table>
				<thead>
					<tr>
						<th>网址名</th>
						<th>URL</th>
						<th>状态</th>
					</tr>
				</thead>
				<tbody>
					<!-- 这里动态生成表格内容 -->
				</tbody>
			</table>
			<button class="add-btn">添加</button>
			<button class="delete-btn">删除</button>
			<button class="lock-btn">锁定</button>
			<button class="unlock-btn">解锁</button>
		</div>
	</div>
	<div class="dialog">
		<form>
			<label>网址名:</label>
			<input type="text" name="name">
			<label>URL:</label>
			<input type="text" name="url">
			<label>状态:</label>
			<select name="status">
				<option value="1">正常</option>
				<option value="2">异常</option>
				<option value="3">已删除</option>
			</select>
			<button type="submit">确定</button>
			<button type="button" class="cancel-btn">取消</button>
		</form>
	</div>
	<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
	<script src="script.js"></script>
</body>
</html>

CSS代码:

.wrapper {
	max-width: 800px;
	margin: 0 auto;
}
.header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 20px;
}
.header h1 {
	margin: 0;
	font-size: 28px;
}
.search-form {
	display: flex;
	align-items: center;
}
.search-form input[type="text"] {
	padding: 5px 10px;
	border: none;
	border-radius: 5px;
	margin-right: 10px;
}
.search-form button {
	padding: 5px 10px;
	border: none;
	border-radius: 5px;
	background-color: #008CBA;
	color: #fff;
	cursor: pointer;
}
.content {
	padding: 20px;
}
table {
	width: 100%;
	border-collapse: collapse;
}
table thead th {
	padding: 10px 5px;
	text-align: left;
	border-bottom: 1px solid #ddd;
}
table tbody td {
	padding: 10px 5px;
	border-bottom: 1px solid #ddd;
}
table tbody td:first-child {
	width: 40%;
}
button {
	padding: 5px 10px;
	border: none;
	border-radius: 5px;
	background-color: #008CBA;
	color: #fff;
	cursor: pointer;
	margin-right: 10px;
}
.dialog {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(0,0,0,0.5);
	display: none;
	justify-content: center;
	align-items: center;
}
.dialog form {
	background-color: #fff;
	padding: 20px;
	border-radius: 5px;
}
.dialog label {
	display: block;
	margin-bottom: 10px;
}
.dialog input[type="text"],
.dialog select {
	padding: 5px 10px;
	border: none;
	border-radius: 5px;
	margin-bottom: 10px;
	width: 100%;
}
.dialog button[type="submit"],
.dialog button[type="button"] {
	padding: 5px 10px;
	border: none;
	border-radius: 5px;
	background-color: #008CBA;
	color: #fff;
	cursor: pointer;
}
.dialog button[type="button"] {
	margin-left: 10px;
	background-color: #ccc;
}

jQuery代码:

$(document).ready(function() {
	// 动态生成表格内容
	$.ajax({
		url: 'get_data.php',
		type: 'GET',
		dataType: 'json',
		success: function(data) {
			var html = '';
			$.each(data, function(index, item) {
				html += '<tr>';
				html += '<td>' + item.name + '</td>';
				html += '<td>' + item.url + '</td>';
				html += '<td>' + item.status + '</td>';
				html += '</tr>';
			});
			$('tbody').html(html);
		},
		error: function() {
			alert('获取数据失败');
		}
	});

	// 点击添加按钮弹出对话框
	$('.add-btn').click(function() {
		$('.dialog').show();
	});

	// 点击取消按钮关闭对话框
	$('.cancel-btn').click(function() {
		$('.dialog').hide();
	});

	// 提交表单数据
	$('form').submit(function(event) {
		event.preventDefault();
		var data = $(this).serialize();
		$.ajax({
			url: 'add_data.php',
			type: 'POST',
			data: data,
			dataType: 'json',
			success: function(data) {
				alert('添加成功');
				$('.dialog').hide();
			},
			error: function() {
				alert('添加失败');
			}
		});
	});

	// 点击删除按钮删除选中行
	$('.delete-btn').click(function() {
		var selected = $('tbody input[type="checkbox"]:checked');
		if (selected.length > 0) {
			if (confirm('确定要删除选中的行吗?')) {
				selected.each(function() {
					$(this).closest('tr').remove();
				});
			}
		} else {
			alert('请选择要删除的行');
		}
	});

	// 点击锁定按钮禁用表格
	$('.lock-btn').click(function() {
		$('table input[type="checkbox"]').prop('disabled', true);
	});

	// 点击解锁按钮启用表格
	$('.unlock-btn').click(function() {
		$('table input[type="checkbox"]').prop('disabled', false);
	});

	// 实时搜索
	$('input[name="search"]').keyup(function() {
		var keyword = $(this).val();
		$('tbody tr').each(function() {
			var name = $(this).find('td:first-child').text();
			if (name.indexOf(keyword) >= 0) {
				$(this).show();
			} else {
				$(this).hide();
			}
		});
	});
});

PHP代码:

<?php
// 获取数据
$data = file_get_contents('data.txt');
if ($data) {
	$data = json_decode($data, true);
} else {
	$data = array();
}

// 处理表单提交
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	$name = trim($_POST['name']);
	$url = trim($_POST['url']);
	$status = intval($_POST['status']);
	if ($name && $url && $status) {
		$newData = array(
			'name' => $name,
			'url' => $url,
			'status' => $status
		);
		array_push($data, $newData);
		$data = json_encode($data);
		file_put_contents('data.txt', $data);
		echo json_encode(array('success' => true));
	} else {
		echo json_encode(array('success' => false));
	}
}

// 输出数据
echo json_encode($data);
按1234567的描述用php+JQ+CSS3写出代码1 HTML页面主要包含一个表格以及添加、删除、锁定、密码解锁搜索等功能的按钮和输入框。表格的列包括网址名、URL、状态等信息。按钮和输入框可以使用HTML的表单元素实现。2 PHP主要负责处理用户提交的表单数据可以使用txt本地来保存收藏的网址信息3 jQuery主要负责处理用户的操作例如点击添加按钮时弹出一个对话框输入网址名和URL以及状态

原文地址: https://www.cveoy.top/t/topic/bnFZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录