<!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(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 + "' />";
col[3].lastChild.value = "确定";
col[3].lastChild.setAttribute("onclick", "upRow('" + rowId + "')");
}
function upRow(rowId){
var row = document.getElementById(rowId).rowIndex; //修改行所在表格中的位置
var col = document.getElementById(rowId).cells;
var text = col[1].firstChild.value;
col[1].innerHTML = text;
col[3].lastChild.value = "修改";
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('del1');"/>
</td>
</tr>
<tr>
<td colspan="4" style="height:30px;">
<input type="button" name="btn" value="增加订单" onclick="addRow();"/>
</td>
</tr>
</table>
</body>
</html>
<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(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 + "' />";
col[3].lastChild.value = "确定";
col[3].lastChild.setAttribute("onclick", "upRow('" + rowId + "')");
}
function upRow(rowId){
var row = document.getElementById(rowId).rowIndex; //修改行所在表格中的位置
var col = document.getElementById(rowId).cells;
var text = col[1].firstChild.value;
col[1].innerHTML = text;
col[3].lastChild.value = "修改";
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('del1');"/>
</td>
</tr>
<tr>
<td colspan="4" style="height:30px;">
<input type="button" name="btn" value="增加订单" onclick="addRow();"/>
</td>
</tr>
</table>
</body>
</html>
解决方案 »
- 新手求教~JS的基本问题(代码~)动动小手,100分到手·~·
- 关于dojo的几个问题,高手来拿分!!
- 该网页的脚本internet explorer运行减慢.如果继续运行,您的计算机运行更慢,是否取消该脚本.
- js parentNode.insertBefore 插入问题
- 一位大侠超厉害的 代码 (使用javascript 调用 C#后台过程). 但我有一点不明,请大家解释.
- 时间格式问题
- 怎么做能让层显示在<IFrame>的上边?
- 请问如何用脚本实现向系统的粘贴板中放入一些字符?
- 请问这个for循环如和实现。
- 随机数组
- 为什么我这一段在FF中可以实现,但是IE中就不行,求高手解答
- 有没有方法能让JS最后加载,以加快大页面的整体载入速度
<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>
t是当前对象,你看你按钮上的方法多了一个this,就是当前点击的对象~·也就是修改按钮
你得传入一下,你看我后来不是在前面加了个this吗 这个就是当前对象
这句话怎么错了 还有我的为什么没有找到当前对象啊