Copy codeThe Code is as follows:
Function jqchk () {// jquery get the check box Value
Var s = '';
$ ('Input [name = "aihao"]: checked'). each (function (){
S + = $ (this). val () + ',';
});
After you click "Submit", you can get the correct selection value, but there will be one more (comma) next to it. This can be checked and removed with substring, or after obtaining the selection value of the check box, it is usually converted to an array before use. Therefore, you can also convert it to an array to remove the last array element.
Copy codeThe Code is as follows:
If (s. length> 0 ){
// Obtain the sequence of the selected checkbox values
S = s. substring (0, s. length-1 );
}
Alert (s = ''? 'You have not selected any content! ': S );
}
</Script>
Directly put the code, mainly to get the checkbox value: Put it in the array, and then connect it to a string
Copy codeThe Code is as follows:
Var chenked = $ ("input [type = 'checkbox']: checked"). val ([]);
Var names = "";
For (var I = 0; I <chenked. length; I ++ ){
Names + = chenked [I]. value + ",";
}
It can be more elegant:
Copy codeThe Code is as follows:
Var arr_v = new Array ();
= $ ("Input [type = 'checkbox']: checked"). each (function (){
Arr_v.push (this. val ());
});
Arr_v.join (',');
That's it.
Copy codeThe Code is as follows:
// This is the focus. The effect of this sentence is the same as that of 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 .');
}
}
);
Java splitting
Copy codeThe Code is as follows:
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;
}
}
Check box for background Query when jquery is modified
Copy codeThe Code is as follows:
Var struids = '$ {useridstr}'; // obtain 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 );
}
}
Drop-down list
Copy codeThe Code is as follows:
Var module = '$ {module }'
$ ("# Module option [value = '" + module + "']"). attr ("selected", "selected ");
Var s = $ ("# parentId"). find ("option: selected"). val ();