jquery automatically fills the check box, that is, marks the check box (true), then obtains the list of checked options through ajax, and then marks the options in the list.
select changes, triggering the function makemoduleSelected(), which is as follows:
//This event (onchange) is triggered when the template drop-down box changes.
function makemoduleSelected(){
clearAll('property');
var modtitlecode = $("#makemodule").val();
$.ajax({
url : ' indexStatisticsAction_getSelect.jsp',
data: { page:'clientindexStatistics.jsp',method:'get_subname_en',modtitlecode:modtitlecode},
success : function(result){
// Judge based on the result return information Whether the login is successful
var results = result.split(",");
//document.getElementById(results[i]).checked = true;
$(".indexStatistics").each( function(){
$(this).find("input").each(function(){
var tempVal = $(this).val();
for(var i=0; i
if(tempVal == results[i]) $(this).attr("checked", true);
}
});
} ; Array, then traverse the tags under the tag , and check the check box (true) when encountering relevant tags. The relevant code for indexStatisticsAction_getSelect.jsp is as follows:
Copy code
String sql = sql2.replace("?modtitlecode?",modtitlecode); sql = sql.replace("?userId?",userId);
System.out.println (sql);
StringBuffer subnames = new StringBuffer();
Db db = new Db();
try {
db.prepareQuery();
ResultSet rs = db.executeQuery( sql);
while (rs!=null && rs.next()) {
subnames.append(rs.getString("subname_en"));
subnames.append(",");
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
db.endQuery();
}
PrintWriter pout = response.getWriter();
pout.write(subnames.toString().substring(0,subnames.length()-1));
pout.flush();
pout.close();
}