博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Jquery操作table
阅读量:7097 次
发布时间:2019-06-28

本文共 10364 字,大约阅读时间需要 34 分钟。

1  $(function () {  2             SetControlDisabled(0, "", true); //控制grid的第一行的所有控件不可用               3             SetControlDisabled("", 1, true); //控制grid的第二列的所有控件不可用         4             SetControlDisabled("", "标题3", true); //控制grid的标题是‘标题3’的那一列的所有控件不可用  5             SetControlDisabled(2, "标题5", true); //控制grid的第三行并且标题是‘标题5’的那一列的所有控件不可用  6             //SetControlDisabled(true);控制grid里面的所有控件不可用       7   8             var controls = findControl(1);//查找第二行的所有控件  9             for (var control in controls) { 10                 alert(controls[control].attr("id")); 11             } 12  13             var targetControls = findControl(0, 1); //查找第一行,第2列的所有控件 14             for (var control in targetControls) { 15                 alert(targetControls[control].attr("id")); 16             } 17  18             String.prototype.trim = function () { 19                 return this.replace(/^(\s|\u3000)+|(\s|\u3000)+$/g, ""); 20             } 21  22             //根据表头标题找到表头所在的列索引 23             function GetTdIndexByTdText(strTdText) { 24                 var targetTdIndex = 0; 25                 $("#grid thead tr").find("th").each(function (index, item) { 26                     if ($(item).text().trim() == strTdText) { 27                         targetTdIndex = index; 28                         return false; 29                     } 30                 }); 31                 return targetTdIndex; 32             } 33             //查找grid里面的控件 34             function findControl() { 35                 var controls = []; 36                 var controlId = null; 37                 if (arguments.length == 1) { 38                     var targetTr = $("#grid tbody tr").eq(arguments[0]); 39                     targetTr.find("td").each(function (index, item) { 40                         $(item).find("input").each(function (i_index, i_item) { 41                             controlId = $(i_item).attr("id") 42                             if (controlId === "") { 43                                 controlId = newGuid(); 44                                 $(i_item).attr("id", controlId); 45                             } 46                             controls[controlId] = $(i_item); 47                         }); 48                         $(item).find("select").each(function (i_index, i_item) { 49                             controlId = $(i_item).attr("id") 50                             if (controlId === "") { 51                                 controlId = newGuid(); 52                                 $(i_item).attr("id", controlId); 53                             } 54                             controls[controlId] = $(i_item); 55                         }); 56                         $(item).find("textarea").each(function (i_index, i_item) { 57                             controlId = $(i_item).attr("id") 58                             if (controlId === "") { 59                                 controlId = newGuid(); 60                                 $(i_item).attr("id", controlId); 61                             } 62                             controls[controlId] = $(i_item); 63                         }); 64                     }); 65                 } else if (arguments.length == 2) { 66                     var targetTr = $("#grid tbody tr").eq(arguments[0]); 67                     var targetTd = targetTr.find("td").eq(arguments[1]); 68                     targetTd.find("input").each(function (index, item) { 69                         controlId = $(item).attr("id") 70                         if (controlId === "") { 71                             controlId = newGuid(); 72                             $(item).attr("id", controlId); 73                         } 74                         controls[controlId] = $(item); 75  76                     }); 77                     targetTd.find("select").each(function (index, item) { 78                         controlId = $(item).attr("id") 79                         if (controlId === "") { 80                             controlId = newGuid(); 81                             $(item).attr("id", controlId); 82                         } 83                         controls[controlId] = $(item); 84  85                     }); 86                     targetTd.find("textarea").each(function (index, item) { 87                         controlId = $(item).attr("id") 88                         if (controlId === "") { 89                             controlId = newGuid(); 90                             $(item).attr("id", controlId); 91                         } 92                         controls[controlId] = $(item); 93  94                     }); 95                 } 96                 return controls; 97             } 98  99             //控制grid里面的控件是否可用100             function SetControlDisabled(rowIndex, colIndex, bolFlag) {101                 //SetGridControlEnabeld(rowIndex,"",bolFlag)             102                 if (rowIndex >= 0 && colIndex == "") {103                     var targetTr = $("#grid tbody tr").eq(rowIndex);104                     targetTr.find("td").each(function (index, item) {105                         SetDisabled(item, bolFlag);106                     });107                 }108                 //SetGridControlEnabeld("",colIndex,bolFlag)               109                 else if (rowIndex == "") {110                     $("#grid tbody tr").each(function (index, item) {111                         var td = null;112                         if (typeof (colIndex) == "string") {113                             td = $(item).find("td").eq(GetTdIndexByTdText(colIndex))114                         } else {115                             td = $(item).find("td").eq(colIndex)116                         }117 118                         SetDisabled(td, bolFlag);119                     });120                 } else if (rowIndex >= 0 && typeof (rowIndex) == "number") {121                     var targetTr = $("#grid tbody tr").eq(rowIndex);122                     var targetTd = null;123                     if (typeof (colIndex) == "string") {124                         targetTd = targetTr.find("td").eq(GetTdIndexByTdText(colIndex))125                     } else {126                         targetTd = targetTr.find("td").eq(colIndex)127                     }128                     SetDisabled(targetTd, bolFlag);129 130                 } else if (arguments.length == 1) {131                     var bolFlag = arguments[0];132                     $("#grid tbody tr").each(function (trIndex, trItem) {133                         $(trItem).find("td").each(function (tdIndex, tdItem) {134                             SetDisabled(tdItem, bolFlag);135                         });136                     });137                 }138             }139 140             //生成 GUID 141             function newGuid() {142                 var guid = "";143                 for (var i = 1; i <= 32; i++) {144                     var n = Math.floor(Math.random() * 16.0).toString(16);145                     guid += n;146                     if ((i == 8) || (i == 12) || (i == 16) || (i == 20))147                         guid += "-";148                 }149                 return guid;150             }151 152             //设置某个容器里面的控件是否可用153             function SetDisabled(container, bolFlag) {154                 $(container).find("input").each(function (index, item) {155                     $(item).attr('disabled', bolFlag);156                 });157                 $(container).find("select").each(function (index, item) {158                     $(item).attr('disabled', bolFlag);159                 });160                 $(container).find("textarea").each(function (index, item) {161                     $(item).attr('disabled', bolFlag);162                 });163             }164         });
View Code

HTML测试代码:

1  
2
3
4
5
8
11
14
17
20
23
24
25
26
27
30
35
38
41
44
47
48
49
52
57
60
63
66
69
70
71
74
79
82
85
88
91
92
93
6 标题1 7 9 标题210 12 标题313 15 标题416 18 标题519 21 标题622
28 29 31 34 36 37 39 40 42 43 45 46
50 51 53 56 58 59 61 62 64 65 67 68
72 73 75 78 80 81 83 84 86 87 89 90
94
View Code

 

转载地址:http://ruhql.baihongyu.com/

你可能感兴趣的文章
windows 环境变量
查看>>
Linux下模拟Http发送的Get和Post请求
查看>>
input checked取值
查看>>
内核参数
查看>>
android中dip、dp、px、sp和屏幕密度
查看>>
2018 Multi-University Training Contest 4
查看>>
流程控制引擎组件化
查看>>
数据库初识--从MySQL 出发
查看>>
5、Web Service-整合CXF
查看>>
c++最短路经典问题
查看>>
vxworks串口的初始化和读写
查看>>
C#-之属性(1)
查看>>
快速幂取模(当数很大时,相乘long long也会超出的解决办法)
查看>>
Drupal8开发教程:认识.info.yml文件
查看>>
面向对象约束常规写法
查看>>
iis8.0 https配置教程
查看>>
Linux(centos7)如何安装Zend Optimizer Zend Guard Loader
查看>>
Scala中隐式参数与隐式转换的联合使用实战详解及其在Spark中的应用源码解析之Scala学习笔记-51...
查看>>
lex&yacc7
查看>>
C++ 语音聊天
查看>>