Code Analysis
Copy Code code as follows:
$ ("#<%= ibsubmit.clientid%>"). Click (function () {
var flag = true;
//alert ($ ("table[id^=ctl]"). length);
//Create a checked arr array to store the checked situation for each RadioButton
var arr = new Array;
$ ("Table[id^=ctl] input[type=radio]"). each (function (i) {
Arr.push (this.checked);
});
//And then create a arrtrue array to filter false arr array
var arrtrue = new Array;
$.each (arr, function (i) {
if (arr[i] = = True) {
Arrtrue.push (arr[i));
}
});
//Of course, you can also use the grep function to simplify filtering arr array operations
//arr = $.grep (arr, function (n, i) {
//return n = = true;
//});
var Grouplen = Math.floor ($ ("table[id^=ctl]"). length + 1/3);
//Finally, it is simple to judge whether the length of the arrtrue is 11.
//Because it is a total of 33 radiobutton, each 3 is a group, the rule is a group of 3 selected 1,//So all options must have 11 radiobutton selected.
if (arrtrue.length!= grouplen) {
flag = false;
}
return false;
});
Complete Code
Copy Code code as follows:
$ (function () {
$ ("#<%= ibsubmit.clientid%>"). Click (function () {
var flag = true;
var arr = new Array;
$ ("Table[id^=ctl] input[type=radio]"). each (function (i) {
Arr.push (this.checked);
});
arr = $.grep (arr, function (n) {
return n = = true;
});
var Grouplen = Math.floor ($ ("table[id^=ctl]"). length + 1/3);
if (arr.length!= grouplen) {
Flag = false;
}
return false;
});
});
Finally attach the Generate table code: (Two generation methods, jquery version, C # version) – (but not to see)
jquery version
Copy Code code as follows:
var array = ["xxxx", "xxxx", "XXX"];
$.each (array, function (i) {
Table.append ("<tr><td>" +
"<input id= ' Cbl_" + i + "'" + "type= ' checkbox ' title= '" + array[0] + "'/>" +
"</td></tr>");
});