更新表行,jQuery [英] Updating a table row, jQuery

查看:154
本文介绍了更新表行,jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新表格中的某一行,已经做了验证器以确保在单击其他按钮后选中复选框时进行1行编辑,到目前为止我写的内容如下:

I need to update a certain row in table, already did "validators" to assure 1 row edit when checkbox is checked after clicking some other button, so far i wrote something like:

$("#btnsavechanges").click(function(){


    $("#meetingspanel tr td").find(":checked").parent().parent().children)(.eq(0).append(document.getElementById("modsub").value);
    $("#meetingspanel tr td").find(":checked").parent().parent().children)(.eq(2).append(document.getElementById("modwhere").value);
    $("#meetingspanel tr td").find(":checked").parent().parent().children)(.eq(3).append(document.getElementById("modwhen").value);
    $("#meetingspanel tr td").find(":checked").parent().parent().children)(.eq(4).append(document.getElementById("modtime").value);
    $("#meetingspanel tr td").find(":checked").parent().parent().children)(.eq(5).append(document.getElementById("modwho").value);
    $("#tblmod").fadeOut("slow");


});

表格如下:

<table id='tblmod' width='80%' align='center' >
<tr bgcolor='white'>
<td width='15%'>
Enter Subject<input type="text" id="modsubject" width="15%">
</td>
<td width='15%'>
Enter Location<input type="text" id="modwhere" width="15%">
</td>
<td width='15%'>
Enter When<input type="text" id="modwhen" width="15%">
</td>
<td width='15%'>
Enter Time<input type="text" id="modtime" width="15%">
</td>
<td width='15%'>
Enter With Who<input type="text" id="modwho" width="15%">
</td>
</tr>
<tr><th align="right" style=border-width:0px><button type="button" id="btnsavechanges" value="Save New Changes" >Save Changes</button></th></tr>
</table>


推荐答案

我建议使用数据绑定框架。我最近一直在使用knockoutjs,我喜欢它。使用Knockout时,我编写的用于执行复杂UI的代码量要小得多。

I would recommend using a data-binding framework. I have been using knockoutjs recently and I like it. The amount of code I write to do complicated UIs is far smaller when using Knockout.

基本上,只需添加数据即可绑定HTML -bind 属性到元素。然后,当有人更改某个值时,会立即在您的viewmodel中更新它。如果您从AJAX请求中提取新数据,它也会更新您的UI。

Basically, you would bind the HTML by just adding a data-bind property to the element. Then, when someone changes a value, it is immediately updated in your viewmodel. If you pull in new data from an AJAX request, it will update your UI too.

此处有更多信息: http://knockoutjs.com/

我强烈建议这样做,因为它可以帮助您编写更清晰,更易于管理的代码,并且做得更快。通过按照要求手动处理所有内容,您将重新发明轮子。

I strongly suggest this as it will help you write cleaner, more manageable code, and do so faster. You are going to be "reinventing the wheel" by handling everything "manually" as you are asking to do.

这篇关于更新表行,jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆