//inputType 1:Checkbox 2:Radio //returnType 1:字符串 2:数组 function GetCheckboxOrRadio(GroupName, inputType = 1, returnType = 1) { if (inputType === 1) inputType = 'checkbox'; else inputType = 'radio'; var packageCodeList; if (returnType === 1) { packageCodeList = $("input:" + inputType + "[name='" + GroupName + "']:checked").map(function (index, elem) { return $(elem).val(); }).get().join(','); } else if (returnType === 2) { packageCodeList = new Array(); $("input:" + inputType + "[name='" + GroupName + "']:checked").each(function () { packageCodeList.push($(this).val());//向数组中添加元素 }); } return packageCodeList; }
function SetSelected(GroupName, value) { if (value) { $(GroupName).children("option").each(function () { var temp_value = $(this).val(); $(this).removeAttr("selected"); if (temp_value === value) { $(this).attr("selected", "selected"); } }); } } function SetCheckboxOrRadio(controlsName, value) { if (value) { $(controlsName).each(function () { var temp_value = $(this).val(); if (temp_value === value) { $(this).attr("checked", "true"); } }); } }