注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

天涯倦客的博客

祝福你朋友永远快乐!

 
 
 

日志

 
 

js控制table  

2012-11-14 22:14:04|  分类: JS |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

$(document).ready(function() {

var pamars = new Array();
            if ($("#opcode").val() == 'add')
                pamars.push('tempGuid=' + encodeURIComponent('<%=Guid.NewGuid().ToString() %>'));

            if ($("#opcode").val() == 'edit') {
                pamars.push('ObjectID=' + '<%=Model.LWLZDJID %>');
            }

            pamars.push('ObjectModule=' + 'LWLZDJ');
            __EditAttachUrl += "/?" + pamars.join('&');

 


            var tableObj = $("#tbLWLZDJAuthor");
            tableObj.find("#Add").click(function() {
                var template = tableObj.find("#trTemplate").clone(true);
                tableObj.append(template);

                template.show().removeAttr("id");
                template.addClass('bbitRow');
                template.find("#Delete").click(function() {
                    template.remove();
                });
            });

            SetAuthorDataTableForString($("#LWLZAuthor").val());


            $(".bbitRow").each(function() {
                var obj = $(this);
                obj.find("#Delete").click(function() {
                    obj.remove();
                });
            });

            //把Json对象转换为字符串
            function OString(O) {
                var S = [];
                for (var i in O) {
                    O[i] = typeof O[i] == 'string' ? '"' + O[i] + '"' : (typeof O[i] == 'object' ? OString(O[i]) : O[i]);
                    S.push(i + ':' + O[i]);
                }
                return '{' + S.join(',') + '}';
            }
            function SetAuthorDataTableForString(jsonStr) {
                if (jsonStr == '') return;
                var list = eval_r(jsonStr);
                var table = $("#tbLWLZDJAuthor");
                for (var i = 0; i < list.length; i++) {
                    var template = table.find("#trTemplate").clone();

                    var rowData = { AuthorName: "", AuthorType1: "", AuthorType2: "" };
                    rowData = list[i];

                    template.attr('id', '');
                    template.find("#AuthorName").val(rowData);
                    template.find("#Type1").val(rowData.AuthorType1);
                    template.find("#Type2").val(rowData.AuthorType2);
                    template.show().addClass('bbitRow');
                    table.append(template);

                }
            }
            //表格转换为JsonString对象
            function GetLWLZAuthorString(table) {
                var data = [];
                $(table).find(".bbitRow").each(function() {

                    var tableRow = $(this)[0];
                    var rowData = { AuthorName: "", AuthorType1: "", AuthorType2: "" };

                    rowData.UserName = $(tableRow).find('#AuthorName').val();
                    rowData.AuthorType1 = $(tableRow).find('#Type1').val();
                    rowData.AuthorType2 = $(tableRow).find('#Type2').val();

                    data.push(OString(rowData));
                });

                return '{fieldDefine:{AuthorName: "", AuthorType1: "", AuthorType2: ""},Data:[' + data.join(',') + ']}';
            }
        });

js控制table

<table id="tbLWLZDJAuthor" width="100%" border="1">
                        <tr>
                            <td colspan="8" style="text-align: left">
                                <a id="Add" style="color: Blue; cursor: pointer">添加</a>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 20%">
                                姓名
                            </td>
                            <td >
                                类型1
                            </td>
                            <td >
                                类型2
                            </td>
                            <td style="width: 30%">
                                操作
                            </td>
                        </tr>
                        <tr id="trTemplate" style="display: none">
                            <td>
                                <input type="text" id="AuthorName" style="border-style: inherit; border-color: #C0C0C0;
                                    width: 100%" value="" />
                            </td>
                            <td>
                                <%=Html.ResourceDictDropDownList("Type1", "DictResource", Beyondbit.HSR.Manage.Common.DicConstant.AuthorType1, Beyondbit.HSR.Manage.Common.DictValue.DictCode, "", new { style = "width:100%" })%>
                            </td>
                            <td>
                                <%=Html.ResourceDictDropDownList("Type2", "DictResource", Beyondbit.HSR.Manage.Common.DicConstant.AuthorType2, Beyondbit.HSR.Manage.Common.DictValue.DictCode, "", new { style = "width:100%" })%>
                            </td>
                            <td>
                                <a href="http://zxianf.blog.163.com/blog/#" id="Delete" style="color: Blue">删除</a>
                            </td>
                        </tr>
                    </table>

  评论这张
 
阅读(561)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017