Assignment actions for radio, checkbox, select:
The code is as follows:
$ ("input[name=a]"). Val (["Entertainment 1"]);
$ ("Input[type=checkbox]"). Val (["Basketball", "game"]);
$ ("select"). Val (["Basketball", "game"]);
Code Analysis:
For radio assignment, the attribute selector obtains the radio;
Assign a value to a CheckBox, the property selector gets the checkbox, and the value is enclosed in brackets [], separated by commas in the middle of multiple values;
Assigns a value to a select, gets a select through the tag Selector,
For radio, checkbox, select Value Operations:
The code is as follows:
var checkvalue = "";
var s = $ ("input[name=a]:checked"). Val ();
$ (": checkbox:checked"). each (function () {
CheckValue + = $ (this). Val ();
});
var selectvalue = "";
$ ("select:selected"). each (function () {
Selectvalue + = $ (this). Val ();
});
Alert ("CheckValue:" + CheckValue + "Radiovalue:" + S + "Selectvalue:" + selectvalue);
Array operations
The first is the normal array (an array indexed as an integer):
$.map (ARR,FN);
Each element in the array calls the FN function to process one at a, and the FN function returns the last resulting array.
The code is as follows:
var arr = [9, 8, 7, 6, 5, 4, 3, 2, 1];
var newarr = $.map (arr, function (item) {return item*2});
alert (newarr);
$.each (ARRAY,FN) array of arrays each element calls the FN function for processing, no return value
The code is as follows:
var arr = [9, 8, 7, 6, 5, 4, 3, 2, 1];
$.each (arr, function (key, value) {Alert ("key:" + key + "value:" + value);});
You can also omit the parameter of a function, this time this can get the value of the current element being traversed
The code is as follows:
var arr = [9, 8, 7, 6, 5, 4, 3, 2, 1];
$.each (arr, function () {alert (this);});
Then there is the array of key values indexed as strings, and for such arrays,
Generally used $.each (ARRAY,FN) to operate:
The code is as follows:
var arr = {"Jim": "One", "Tom": "One", "Lilei": "13"};
$.each (arr, function (key, value) {alert ("Name:" +key+ "Age:" +value);});