87,989
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled Document</title>
<style type="text/css">
table {
font-size: 13px;
line-height: 25px;
border-top: 1px solid #333;
border-left: 1px solid #333;
width: 400px;
border-right: 1px solid #333;
border-bottom: 1px solid #333;
text-align: center;
}
.title {
font-weight: bold;
background-color: #cccccc;
}
input {
background-color: #cccccc;
}
</style>
<script type="text/javascript">
function addRow(){
var rowTable = document.getElementById("myTable");
var rowindex = rowTable.rows.length - 1;
var insertRow = rowTable.insertRow(rowindex);
insertRow.id = "row" + rowindex;
var col1 = insertRow.insertCell(0);
col1.innerText = "抗疲劳神奇钛项圈";
var col2 = insertRow.insertCell(1);
col2.innerHTML = rowindex;
var col3 = insertRow.insertCell(2);
col3.innerHTML = "¥49.9"
var col4 = insertRow.insertCell(3);
col4.innerHTML = "<input type='button' value='删除' onclick='deleteRow(" + "\"" + insertRow.id + "\"" + ")'/>"
}
function deleteRow(rowID){
var rowTable = document.getElementById(rowID).rowIndex;
document.getElementById("myTable").deleteRow(rowTable);
}
function editRow(t,rowId){
alert("upRow('" + rowId + "')");
var row = document.getElementById(rowId).rowIndex; //修改行所在表格中的位置
var col = document.getElementById(rowId).cells;
var text = col[1].innerHTML;
col[1].innerHTML = "<input name='num" + row + "' style='width:40px;' type='text' value='" + text + "' />";
t.value = "确定";
t.onclick = function(){upRow(t,rowId)};
//t.setAttribute("onclick", "upRow('" + rowId + "')");
}
function upRow(t,rowId){
var row = document.getElementById(rowId).rowIndex; //修改行所在表格中的位置
var col = document.getElementById(rowId).cells;
var text = col[1].firstChild.value;
col[1].innerHTML = text;
t.value = "修改";
t.onclick = function(){editRow(t,rowId)};
//col[3].lastChild.setAttribute("onclick", "editRow('" + rowId + "')");
}
</script>
</head>
<body>
<table id="myTable" width="352" border="1" cellpadding="0" cellspacing="0">
<td>
商品名称
</td>
<td>
数量
</td>
<td>
价格
</td>
<td>
操作
</td>
</tr>
<tr id="del1">
<td>
防滑真皮休闲鞋
</td>
<td>
12
</td>
<td>
¥568.50
</td>
<td>
<input type="button" value="删除" onclick="deleteRow('del1');"/>
<input id="edit1" type="button" value="修改" onclick="editRow(this,'del1');"/>
</td>
</tr>
<tr>
<td colspan="4" style="height:30px;">
<input type="button" name="btn" value="增加订单" onclick="addRow();"/>
</td>
</tr>
</table>
</body>
</html>