Jquery automatically fills the checkbox with true
- 2020-03-30 02:27:35
- OfStack
Jquery automatically fills the checkbox with a checkbox (true), and then gets the list of checkboxes through ajax, and then types the options in the list.
Select changes to trigger the function makemoduleSelected(), which is as follows:
This function makes an ajax-style request to indexstatisticsaction_getselection.jsp, returns a string, splits the modified string into an array of strings, and then iterates through the label < Div class = "indexStatistics >" The tag below is checked (true) when the relevant tag is encountered. The relevant code for indexstatisticsaction_getselection.jsp is as follows:
A drop-down box <select name="makemodule" id="makemodule" style='width:130px' onchange='makemoduleSelected()'>
<option value='1'>1</option>
</select>
Select changes to trigger the function makemoduleSelected(), which is as follows:
//This event 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){
//The result returns information to determine whether the login was 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<results.length; i++){
if(tempVal == results[i]) $(this).attr("checked", true);
}
});
});
}
});
}
This function makes an ajax-style request to indexstatisticsaction_getselection.jsp, returns a string, splits the modified string into an array of strings, and then iterates through the label < Div class = "indexStatistics >" The tag below is checked (true) when the relevant tag is encountered. The relevant code for indexstatisticsaction_getselection.jsp is as follows:
//Gets the index for the template
if(method.equals("get_subname_en")){
String modtitlecode = request.getParameter("modtitlecode");
if(modtitlecode.equals("-------")) return;
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();
}