function jqchk(){ //jquery gets the checkbox value
var s='';
$('input[name="aihao"]:checked').each(function(){
s =$(this).val() ',';
});
After clicking "Submit", you can get the correct selection value, but there is one more after it, (English comma). This can be detected and then removed with substring, or obtained After selecting the value in the check box, it is generally converted into an array before use, so you can also remove the last array element after converting into an array.
if (s.length > 0) {
//Get the selected checkbox value sequence
s = s.substring(0,s.length - 1);
}
alert(s==''?'You haven't selected anything yet! ':s);
}
Go directly to the code, mainly to get the checkbox value: put it into an array and then concatenate it into a string
var chenked=$("input[type='checkbox ']:checked").val([]);
var names = "";
for(var i=0;inames = 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(',');
i.e. Okay
//This is the key point, this sentence is the same as the following The first sentence has the same effect
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 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;
}
}
Select the background query checkbox when modifying jquery
var struids='${useridstr}'; //Get data in the background
alert(struids);
if(struids!='')
{
var str=struids.split( ",");
for(var j=0;j{
$(":checkbox[value='" str[j] "']"). attr("checked",true);
}
}
Drop-down box
var module='${module}'
$("#module option[value='" module "']").attr ("selected","selected");
var s = $("#parentId").find("option:selected").val();