首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

jQuery 如何获取表格里面的值

2013-08-16 
jQuery 怎么获取表格里面的值源码:div classtitle_ch3 classtitle_right2人员列表/h3a class

jQuery 怎么获取表格里面的值


源码:


<div class="title_c">
<h3 class="title_right2">
人员列表

</h3>
<a class="btn_small f_right mright10" href="#"><b
class="add_select"></b>批量导入</a><a
class="btn_small f_right mright10"
onclick="showpop('del')"><b class="del"></b>删除</a>
<!-- onclick="showpop('add_p')" -->
<a class="btn_small f_right mright10" id="edit"><b class="edit"></b>修改</a>
<a class="btn_small f_right mright10"
onclick="showpop('add_p')"><b class="add"></b>新增</a>

</div>

<div class="mtop10">
<div class="over_x_sco">
<table width="100%" cellpadding="0" cellspacing="1"
class="table_list3 table_border_line evenRow">

<tr class="background_th">
<th align="center">
<input type="checkbox" name="checkbox4" id="checkbox4" />
</th>
<th>

</th>
<th>
员工编号
</th>
<th>
姓名
</th>
<th>
集采供应商标识
</th>
<th>
手机
</th>
<th>
国籍
</th>
<th>
性别
</th>
<th>
所在组
</th>
<th>
有效起始日期
</th>
<th>
有效终止日期
</th>
</tr>
<s:iterator value="pm.rows" var="emp" status="ss">
<tr>
<td align="center" valign="middle">
<input type="checkbox" name="checkbox5" id="checkbox5" />
</td>
<td>
<s:property value="#ss.count"/>
</td>
<td>
<s:property value="#emp.id"/>
</td>
<td>
<s:property value="#emp.empName"/>


</td>
<td>
<s:property value="#emp.supplierId"/>
</td>
<td>
<s:property value="#emp.mobile"/>
</td>
<td>
<s:property value="#emp.country"/>
</td>
<td>
<s:property value="#emp.sex"/>
</td>
<td>
<s:property value="#emp.group"/>
</td>
<td>
<s:date name="#emp.startDate" format="yyyy-MM-dd"/>
</td>
<td>
<s:date name="#emp.endDate" format="yyyy-MM-dd"/>
</td>
</tr>
</s:iterator>
</table>
</div>



下面整个表格都是从集合里面循环出来的。。
请问  怎么当选中一条数据前的多选框并点击修改时得到  后面的整行数据  谁叫我写一下
[解决办法]
           function Edit() {
               $('table tr:gt(0) input:checked').each(function () {
                   var tr = $(this).closest('tr'), td = tr.find('td:gt(0)');
                   td.each(function () {alert(this.innerHTML) });
               })
           }

[解决办法]
首先,如果tr是循环的话,你的checkbox的ID重复了,不过没什么大问题。

大概流程就是,给修改按钮绑定click事件,事件函数内,判断列表中checkbox被选中的数量,如果允许修改多个,那就判断 != 1非法,如果不允许,只判断< 1非法。

如果允许修改多个,就循环取到的checkbox依次去找对应的值,如果只允许单个,直接选取。
大概的代码如下,未经验证也不够优雅,你参考下。


<script type="text/javascript">


$("#edit").bind("click",function(){
var cblist = $(".checkbox5[checked=true]");
if (cblist < 1){
alert("请先选中再操作");
}
cblist.each(function(){
var tr = $(this).parent().parent();
//找到了这行记录,依次用find去找子元素的值
});
});
</script>

热点排行
Bad Request.