<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
}
.wrap {
width: 410px;
margin: 100px auto 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
border: 1px solid #c0c0c0;
}
th,
td {
border: 1px solid #d0d0d0;
color: #404060;
padding: 10px;
}
th {
background-color: #09c;
font: bold 16px "微软雅黑";
color: #fff;
}
td {
font: 14px "微软雅黑";
}
td a.get {
text-decoration: none;
}
a.del:hover {
text-decoration: underline;
}
tbody tr {
background-color: #f0f0f0;
}
tbody tr:hover {
cursor: pointer;
background-color: #fafafa;
}
.btnAdd {
width: 110px;
height: 30px;
font-size: 20px;
font-weight: bold;
}
.form-item {
height: 100%;
position: relative;
padding-left: 100px;
padding-right: 20px;
margin-bottom: 34px;
line-height: 36px;
}
.form-item > .lb {
position: absolute;
left: 0;
top: 0;
display: block;
width: 100px;
text-align: right;
}
.form-item > .txt {
width: 300px;
height: 32px;
}
.mask {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background: #000;
opacity: 0.6;
display: none;
}
#j_hideFormAdd {
width: 22px;
height: 22px;
cursor: pointer;
text-align: center;
line-height: 22px;
font-size: 18px;
}
#j_hideFormAdd:hover {
background-color: skyblue;
}
.form-add {
position: fixed;
top: 30%;
left: 50%;
margin-left: -197px;
padding-bottom: 20px;
background: #fff;
display: none;
}
.form-add-title {
background-color: #f7f7f7;
border-width: 1px 1px 0 1px;
border-bottom: 0;
margin-bottom: 15px;
position: relative;
}
.form-add-title span {
width: auto;
height: 18px;
font-size: 16px;
font-family: 宋体;
font-weight: bold;
color: rgb(102, 102, 102);
text-indent: 12px;
padding: 8px 0px 10px;
margin-right: 10px;
display: block;
overflow: hidden;
text-align: left;
}
.form-add-title div {
width: 16px;
height: 20px;
position: absolute;
right: 10px;
top: 6px;
font-size: 30px;
line-height: 16px;
cursor: pointer;
}
.form-submit {
text-align: center;
}
.form-submit input {
width: 170px;
height: 32px;
}
</style>
</head>
<body>
<!--按钮和表单-->
<div class="wrap">
<div>
<input type="button" value="添加数据" id="j_btnAddData" class="btnAdd"/>
</div>
<table>
<thead>
<tr>
<th>名称</th>
<th>简介</th>
<th>以了解</th>
</tr>
</thead>
<tbody id="j_tb">
<tr>
<td>巴索罗缪·大熊</td>
<td>原王下七武海之一。原索尔贝王国国王。绰号“暴君”,世人传言从前是一个纵横跋扈的凶残海贼。</td>
<td><a href="javascrip:;" class="get">delete</a></td>
</tr>
<tr>
<td>西尔巴兹·雷利</td>
<td>外号“冥王”,原罗杰海贼团的副船长,被称为“海贼王的右腕”。</td>
<td><a href="javascrip:;" class="get">delete</a></td>
</tr>
<tr>
<td>新世界</td>
<td>伟大航路后半段的海域。新世界的霸主是四皇,这里是最困难最危险的海域。</td>
<td><a href="javascrip:;" class="get">delete</a></td>
</tr>
<tr>
<td>佐乌岛</td>
<td>岛上的居民为皮毛族。该岛建基于千年古象的背上,随着大象的移动而改变位置</td>
<td><a href="javascrip:;" class="get">delete</a></td>
</tr>
</tbody>
</table>
</div>
<!--遮罩层-->
<div id="j_mask" class="mask"></div>
<!--添加数据的表单-->
<div id="j_formAdd" class="form-add">
<div class="form-add-title">
<span>添加数据</span>
<div id="j_hideFormAdd">×</div>
</div>
<div class="form-item">
<label class="lb" for="j_txtLesson">名称:</label>
<input class="txt" type="text" id="j_txtLesson" placeholder="请输入名称">
</div>
<div class="form-item">
<label class="lb" for="j_txtBelSch">简介:</label>
<input class="txt" type="text" id="j_txtBelSch" placeholder="内容">
</div>
<div class="form-submit">
<input type="button" value="添加" id="j_btnAdd">
</div>
</div>
<script src="./js/jquery-3.0.0.js"></script>
<script>
$('#j_btnAddData').click(function(){
$('.mask').show();
$('.form-add').show();
});
$('#j_hideFormAdd').click(function(){
$('.mask').hide();
$('.form-add').hide();
});
$('#j_btnAdd').click(function(){
var txtLesson=$('#j_txtLesson').val();
var txtBelSch=$('#j_txtBelSch').val();
var $trNew=$('<tr>'+
'<td>'+txtLesson+'</td>'+
'<td>'+txtBelSch+'</td>'+
'<td><a href="javascrip:;" class="get">delete</a></td>'+
'</tr>');
$trNew.find('.get').click(function(){
$trNew.remove();
});
$('#j_tb').append($trNew);
$('#j_hideFormAdd').click();
});
$('#j_tb .get').click(function(){
$(this).parent().parent().remove();
});
</script>
</body>
</html>
动态数据添加和删除
最新推荐文章于 2024-07-10 10:14:49 发布