标签:creat confirm mode cli jquer edit pre hid 点击
实现了动态添加,删除。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.hide{
display:none;
}
.model{
position:fixed;
top:50%;
left:50%;
width:500px;
height:400px;
margin-left:-250px;
margin-top:-250px;
background-color:#eeeeee;
z-index:10;
}
.shadow{
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
opacity:0.6;
background-color:black;
z-index:9;
}
</style>
</head>
<body>
<a onclick="addElement();">添加</a>
<table border="1px" id="tb">
<tr>
<td>1.1.1.11</td>
<td>80</td>
<td>
<a class="edit">编辑</a> | <a class="del">删除</a>
</td>
</tr>
<tr>
<td>1.1.1.12</td>
<td>80</td>
<td>
<a class="edit">编辑</a> | <a class="del">删除</a>
</td>
</tr>
<tr>
<td>1.1.1.13</td>
<td>80</td>
<td>
<a class="edit">编辑</a> | <a class="del">删除</a>
</td>
</tr>
</table>
<div class="model hide">
<div>
<input name="hostname" type="text"/>
<input name="port" type="text"/>
<input type="text"/>
</div>
<div>
<input type="button" value="取消" onclick="cancelModel();"/>
<input type="button" value="确定" onclick="confirmModel();"/>
</div>
</div>
<div class="shadow hide"></div>
<script src="jquery-1.12.4.js"></script>
<script>
$(‘.del‘).click(function(){
$(this).parent().parent().remove();
})
function confirmModel(){
var tr=document.createElement(‘tr‘);
var td1=document.createElement(‘td‘);
td1.innerHTML=‘1.1.1.333‘;
var td2=document.createElement(‘td‘);
td2.innerHTML=‘8001‘;
$(tr).append(td1);
$(tr).append(td2);
$(‘#tb‘).append(tr);
$(".model,.shadow").addClass(‘hide‘);
$(‘.model input[type="text"]‘).each(function(){
//var temp="<td>.."
var td=document.createElement(‘td‘);
td.innerHTMl=‘用户输入的值‘;
})
}
function addElement(){
//$(‘.model‘).removeClass(‘hide‘);
//$(‘.shadow‘).removeClass(‘hide‘);
$(‘.model,.shadow‘).removeClass(‘hide‘);
}
function cancelModel(){
$(‘.model,.shadow‘).addClass(‘hide‘);
$(‘.model input[type="text"]‘).val("");
}
$(‘.edit‘).click(function(){
$(‘.model,.shadow‘).removeClass(‘hide‘);
//this 当前点击的标签
var tds=$(this).parent().prevAll();
var port=$(tds[0]).text();
var host=$(tds[1]).text();
$(‘.model input[name="hostname"]‘).val(host);
$(‘.model input[name="port"]‘).val(port);
//循环获取tds中的内容,赋值给input标签里面的value。cancel.log(tds[0])=80;
});
</script>
</body>
</html>
标签:creat confirm mode cli jquer edit pre hid 点击
原文地址:http://www.cnblogs.com/momo8238/p/7468923.html