Home > Web Front-end > JS Tutorial > Introduction to the functions and usage examples of RadioButtonList in jQuery_jquery

Introduction to the functions and usage examples of RadioButtonList in jQuery_jquery

WBOY
Release: 2016-05-16 17:24:31
Original
1028 people have browsed it

Code analysis

Copy code The code is as follows:

$ ("#<%= ibSubmit.ClientID%>").click(function() {
var flag = true;
//alert($("table[id^=ctl]"). length);
//Create a checked arr array to store the checked status of each radiobutton
var arr = new Array;
$("table[id^=ctl] input[type= radio]").each(function(i) {
arr.push(this.checked);
});

//Then create an 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 the filtering arr array operation

//arr = $.grep( arr, function(n, i) {
//return n == true;
//});

var groupLen = Math.floor($("table[id^=ctl ]").length 1 / 3);

//Finally, let’s be simple, just judge whether the length of arrTrue is 11.

//Because there are 33 radiobuttons in total , each group is a group of 3, and the rule is to choose 1 out of 3 in a group, //so all 11 radiobuttons must be selected.
if (arrTrue.length != groupLen) {
flag = false. ;
}
return false;

});

Full code
Copy code The code is 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, the code to generate Table is attached: (two generation methods, JQuery version, C# version ) – (can be viewed or not)

jQuery version
Copy code The code is as follows :

var array = ["XXXX",""XXXX","XXX"];
$.each(array, function(i) {
table.append(" "
""
"< ;/td>");
});
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template