日期:2014-05-16 浏览次数:20441 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<table id="myTable" border="1" >
<tr>
<td>商品名称</td>
<td>数量</td>
<td>价格</td>
<td>操作</td>
</tr>
<tr>
<td>防滑真皮休闲鞋</td>
<td>12</td>
<td>¥568.50</td>
<td><input type="button" value="删除" onclick="Delete()" id="delete" />
<input type="button" value="修改" onclick="Update()" id="update" /></td>
</tr>
<tr>
<td>抗疲劳神奇钛项圈</td>
<td>2</td>
<td>¥49.00</td>
<td><input type="button" value="删除" onclick="Delete()" id="delete" />
<input type="button" value="修改" onclick="Update()" id="update" /></td>
</tr>
</table>
<input type="button" value="增加订单" onclick="Add()" />
</body>
<script type="text/javascript">
function Delete(){
//删除订单
var x = document.getElementById("myTable");
x.deleteRow(this);
}
function Update(){
//修改订单
/**
#ERROR
1.输入之后的值保存.
2.值传递给新值.
**/
var inputs = document.createElement("input");
var texts = inputs.setAttribute("type","text");
var x = document.getElementById("myTable").rows[1];//行对象
x.cells[1].innerHTML = '<input type="text" id="te" />' ;//获取这个地方的值.
document.getElementById("update").value="确定";//修改显示文字
// var y = document.getElementById("myTable").rows[1];
var xk = document.getElementById("te").defaultValue;//!~~~~拿不到值
}
function Add(){
//增加订单
var s = document.getElementById("myTable").insertRow(2);
var newCell = s.insertCell(0);
newCell.innerHTML="抗疲劳神奇钛项圈";
var newCell1 = s.insertCell(1);
newCell1.innerHTML="5";
var newCell2 = s.insertCell(2);
newCell2.innerHTML="¥20";
var newCell3 = s.insertCell(3);
newCell3.innerHTML='<input type="button" value="删除" onclick="Delete()" id="delete" /><input type="button" value="修改" onclick="Update()" id="update" />';
}
</script>
</html>