您好,登錄后才能下訂單哦!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery3.js"></script>
<style>
.modal{
position: fixed;
top: 50%;
left: 50%;
height: 400px;
width: 400px;
margin-left: -250px;
margin-top: -250px;
background-color: #dddddd;
z-index: 10;
}
.shadow{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
opacity: 0.6;
background-color: black;
z-index: 9;
}
.hide{
display: none;
}
</style>
</head>
<body>
<input type="button" onclick="addElement()" value="添加">
<table border="1">
<thead>
<tr>
<th >序號(hào)</th>
<th >IP</th>
<th >端口</th>
<th >操作</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1.1.1.1</td>
<td>80</td>
<td><a class="edit">編輯</a> | <a class="delete">刪除</a></td>
</tr>
<tr>
<td>2</td>
<td>2.2.2.2</td>
<td>80</td>
<td><a class="edit">編輯</a> | <a class="delete">刪除</a></td>
</tr>
<tr>
<td>3</td>
<td>3.3.3.3</td>
<td>80</td>
<td><a class="edit">編輯</a> | <a class="delete">刪除</a></td>
</tr>
</tbody>
</table>
<div class="shadow hide"></div>
<div class="modal hide">
<div>
<span>序號(hào):</span><label id="id"></label>
<input id="hostname" name="hostname" type="test">
<input id="port" name="port" type="test">
<br>
<input type="button" value="提交" onclick="subbiteData()">
<input type="button" value="取消" onclick="cancalModal()">
</div>
</div>
<script>
function addElement() {
$(".shadow,.modal").removeClass('hide')
$("#hostname").val("")
$("#port").val("")
}
function cancalModal() {
$(".shadow,.modal").addClass('hide')
}
$('.edit').click(function () {
$(".shadow,.modal").removeClass('hide')
//this當(dāng)表當(dāng)前點(diǎn)擊的標(biāo)簽
var tds = $(this).parent().prevAll()
//獲取<td>內(nèi)容</td>獲取中間的內(nèi)容
//賦值給input標(biāo)簽中的value值
//$(tds[0]).text() 獲取文本內(nèi)容
//$(tds[0]).text('xxx') 設(shè)置文本內(nèi)容
//(..).val() 獲取相對(duì)應(yīng)類型的value值
//(..).val(..) 設(shè)置相對(duì)應(yīng)類型的value值
var port = ($(tds[0]).text())
var hostname = ($(tds[1]).text())
var id = ($(tds[2]).text())
//其中一種比較簡(jiǎn)易的寫(xiě)法
// $("#hostname").val(hostname)
// $("#port").val(port)
//通過(guò)獲取標(biāo)簽屬性操作
$('.modal input[name="hostname"]').val(hostname)
$('.modal input[name="port"]').val(port)
$("#id").text(id)
})
function subbiteData() {
//暫沒(méi)提交功能
var id = $("#id").text()
console.log(id)
}
</script>
</body>
</html>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。