欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jquery获取tr中控件值并操作tr实现思路

程序员文章站 2022-05-03 20:32:56
代码如下:

代码如下:

<table style="width: 100%; height: 100%" border="1">
<caption>
material/special tool rental/tool cantainer/transportation/mobile</caption>
<tbody><tr>
<td>
project no
</td>
<td>
<input type="hidden" name="hidprojectinnerid" id="hidprojectinnerid">
<input name="txtprojectno" type="text" id="txtprojectno" class="error"><a href="javascript:void(0)" onclick="selectproject();">选择</a>
</td>
<td>
final custome:
</td>
<td>
<span id="labfinalcustome">label</span>
</td>
<td>
order no.
</td>
<td>
<span id="laborderno">label</span>
</td>
<td>
project leaing time:
</td>
<td>
<span id="labprojectleaingtime">label</span>
</td>
</tr>
<tr>
<td colspan="8">
exchange rate:8.3000
</td>
</tr>
<tr align="center">
<td>
item
</td>
<td colspan="2">
description
</td>
<td>
qty
</td>
<td>
unit
</td>
<td>
total
</td>
<td>
remark
</td>
<td>
<a id="newitem" href="javascript:void(0)">newitem</a>
</td>
</tr>
</tbody><tbody id="tbitem">
<tr align="center">
<td>
</td>
<td colspan="2">
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>

</td>
</tr>
<tr id="tbitem1" align="center"><td><select id="selitem" name="item"><option value="material">material</option><option value="mobile">mobile</option><option value="others">others</option><option value="specialtoolrental">special tool rental</option><option value="toolcontainer">tool container</option><option value="transportation">transportation</option><option value="workinghours">workinghours</option></select></td><td colspan="2"><input id="txtdescription" style="width:90%" type="text" name="item"></td><td><input id="txtqty" type="text" name="item"></td><td><input id="txtunit" type="text" name="item"></td><td><input id="txttotal" type="text" name="item"></td><td><input id="txtremark" type="text" name="item"></td><td><a href="javascript:;saveitem('tbitem1')">保存</a> | <a href="javascript:;delitem('tbitem1')">删除</a> <input id="txtinnerid" type="hidden" name="item"></td></tr></tbody>
</table>


. 代码如下:


function saveitem(index) {
var tr = $("tr[id=" + index + "]");
var innerid = tr.find('input[id$=txtinnerid]').val();
var item = tr.find("select[id*=selitem]").val();
var des = tr.find('input[id$=txtdescription]').val();
var qty = tr.find('input[id$=txtqty]').val();
var unit = tr.find('input[id$=txtunit]').val();
var total = tr.find('input[id$=txttotal]').val();
var remark = tr.find('input[id$=txtremark]').val();
//alert(innerid + "/" + item + des + qty + unit + total + remark);
//验证项目编号
var proinnerid = $("#hidprojectinnerid").val();
if (proinnerid == "") {
$("#txtprojectno").removeclass("field");
$("#txtprojectno").addclass("error");
return false;
}
/*
jquery.ajax({
type: 'get',
url: '../handler/projectreport.ashx',
data: { "key": "save", "proinnerid": $("#hidprojectinnerid").val(), "innerid": innerid, "type": type, "content": content, "startdate": startdate, "enddate": enddate, "remark": remark },
cache: false,
success: function (result) {
var jsonobj = eval(result);
if (jsonobj[0].result == "true")
alert("sueecss");
else
alert("error");
}
});
*/
}
function delitem(index) {
var tr = $("tr[id=" + index + "]");
//var innerid = tr.find('input[id$=txtinnerid]').val();
$("tr[id=" + index + "]").remove();
}