java script
如何在单击修改的时候把数量放在文本框里
java?script
<script type="text/javascript">
function upd(?){
}
</script>
</head>
<body>
<table id="table1" border="1px">
<tr style="text-align:center; font-weight:bold;">
<td>商品名称</td>
<td>数量</td>
<td>单价</td>
<td>操作</td>
</tr>
<tr id="tr2">
<td>玫瑰保湿睡眠面膜</td>
<td>5</td>
<td>¥48</td>
<td><input type="button" value="删除" onclick="dele('tr2')"/>
<input id="t1" type="button" value="修改" onchange="upd(?)" /></td>
</tr>
<tr style="text-align:center">
<td colspan="4"><input type="button" value="增加订单" /></td>
</tr>
</table>
<html>
<head>
<script type="text/javascript">
function update(){
var cnt = document.getElementById("cnt");
cnt.innerHTML = "<input type='text' value=" + cnt.innerHTML + " id='cntInput' onchange='confirmUpdate()'/>";
}
function confirmUpdate(){
var r=confirm("确认修改!");
if (r){
//alert("You pressed OK!");
var newCnt = document.getElementById("cntInput").value;
//alert(newCnt);
var cnt = document.getElementById("cnt");
cnt.innerHTML = newCnt;
}
}
</script>
</head>
<body>
<table border="1">
<tr>
<td id="cnt">123</td>
</tr>
</table>
<br />
<input type="button" onclick=update()
value="修改" />
</body>
</html>
<script type="text/javascript">
function upd(sls){
var sl=document.getElementById("sl"); //选中表中的哪一列
sl.innerHTML="<input type='text' value='"+sls+"'/>";//动态添加一个输入框,输入框中的默认值为之前的5
}
</script></head><body><table id="table1" border="1px"> <tr style="text-align:center; font-weight:bold;"> <td>商品名称</td> <td>数量</td> <td>单价</td> <td>操作</td> </tr> <tr id="tr2"> <td>玫瑰保湿睡眠面膜</td> <td id="sl">5</td> <td>¥48</td> <td><input type="button" value="删除" onclick="dele('tr2')"/> <input id="t1" type="button" value="修改" onchange="upd('5')" /></td> </tr> <tr style="text-align:center"> <td colspan="4"><input type="button" value="增加订单" /></td> </tr></table>