function fnIsModified(){ var $userName = $('.ltable tr:nth-child(2)').find('td:nth-child(2)'),userNameText = $userName.text(),newText = $('.userName').val(),flag=false;if(newText !== userNameText){$userName.text(newText);flag=true;}else{};return flag;};$(document).on('click','.userEditBtn',function(event) {event.preventDefault();userEdit.dialogShow();var userName = $(this).parents('tr').find('td:nth-child(2)').text();$('.userName').attr('value',userName); });
2 回答
一只斗牛犬
TA贡献1784条经验 获得超2个赞
胡说叔叔
TA贡献1804条经验 获得超8个赞
你可以为“修改”按钮写一个onclick函数,然后用this传值,这样就能判断是点击了那行的修改按钮,代码如下:
<a href="javascript:void(0)" onclick="onModified(this)">修改</a> |
function onModified(btn){ var uname = $(btn).parent("td").parent("tr").find("td:eq(1)"); alert('我要修改用户名称为' + uname + '的一行'); /** 其它代码 **/} |
另外建议你不要使用形如 $('.ltable tr:nth-child(2)').find('td:nth-child(2)')这样的jQuery选择器,因为class选择器是jQuery中效率最低下的选择器,当表格数据很大时,用这样的选择器会耗费很大的系统资源。
添加回答
举报
0/150
提交
取消






