A brief introduction to the functions and usages of RadioButtonList in jquery _jquery

Source: Internet
Author: User

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>");
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.