Original: jquery Gets the selected check box value separately
function Jqchk () {//jquery Gets the check box value
var s= ';
$ (' input[name= ' Aihao "]:checked '). each (function () {
s+=$ (This). Val () + ', ';
});
Click "Submit", you can get the correct selection of values, but one more, (comma), this can be detected and then removed with substring, or get to the check box selection value is generally transferred to the group before use, so you can also be transferred to the group after the last array element.
if (s.length > 0) {
Gets the selected CheckBox value sequence
s = s.substring (0,s.length-1);
}
Alert (s== '? ') You have not selected any content yet! ': s);
}
</script>
Directly on the code,The main way to get a checkbox value is to put it in an array and concatenate it into a string
[b]
var chenked=$ ("Input[type= ' checkbox ']:checked"). Val ([]);
var names = "";
for (Var i=0;i<chenked.length;i++) {
Names + = Chenked[i].value + ",";
}
Can be more elegant:
var arr_v = new Array ();
=$ ("input[type= ' checkbox ']:checked"). each (function () {
Arr_v.push (This.val ());
});
Arr_v.join (', ');
That'll do it.
This is the focus, the sentence is the same as the first sentence below
var selecteditems = new Array ();
$ ("input[@name = ' itemselect[] ']:checked"). each (function () {Selecteditems.push ($ (this). Val ());});
if (selecteditems. length = = 0)
Alert ("Please select item (s) to delete.");
Else
$.ajax ({
Type: "POST",
URL: "/ajax_do_something.php",
Data: "items=" + selecteditems.join (' | '),
DataType: "Text",
Success:function (Request) {
Document.location.reload ();
},
Error:function (request,error) {
Alert (' Error deleting item (s), try again later. ');
}
}
); [/b]
Java split
String names = null;
String name1 = null;
String name2 = null;
names = Request.getparameter ("names");
string[] name = Names.split (",");
for (String x:name) {
if ("Zhangsan". Equals (x)) {
name1 = x;
}
if ("Lisi". Equals (x)) {
name2 = x;
}
}
jquery changes when you select the check box for a background query
var struids= ' ${useridstr} '; Get data in the background
alert (struids);
if (struids!= ")
{
var str=struids.split (",");
for (Var j=0;j<str.length;j++)
{
$ (": Checkbox[value= '" "+str[j]+" '] "). attr (" Checked ", true);
}
}
check box
drop-down box
var module= ' ${module} '
$ ("#module option[value= '" + module + "']"). attr ("Selected", "Selected");
var s = $ ("#parentId"). Find ("option:selected"). Val ();
- jquery Learning Classic Crash technical data. RAR (3.3 MB)
- Download number of times: 50033