日期:2014-05-17 浏览次数:20723 次
<html>
<body>
<div>
<select name="year" id="year" onchange="schange()">
<option value="33" selected>33</option>
<option value="44">44</option>
<option value="55">55</option>
</select>
</div>
<div id="createCheckBox"></div>
<body>
</html>
<script>
function schange(){
var year=document.getElementById('year').value;
jQuery.post('xxxxx.action',{year:year},function (data) {
var createCheckBox = document.getElementById("createCheckBox") ;
var list = data.list2 ;
for(var i=0;i<list.length;i++) {
var checkbox=document.createElement("input");
checkbox.type="checkbox";
checkbox.id=list[i].game_id;
checkbox.innerText=list[i].name;
createCheckBox.appendChild(checkbox);
}
},'json');
}
</script>
下面是xxx。action的代码
JSONObject json = new JSONObject();
json.put("list2", list2);
super.response().setCharacterEncoding("UTF-8");
try {
PrintWriter printWrite = super.response().getWriter();
printWrite.write(json.toString());
printWrite.flush();
printWrite.close();
} catch (IOException e) {
logger.error(e, e);
}finally{
super.response().getWriter().close();
}
<html>
<body onload="change()">
<div>
<select name="year" id="year" onchange="change()">
<option value="33" selected>33</option>
<option value="44">44</option>
<option value="55">55</option>
</select>
</div>
<div>
<input type="checkbox" id="33">我是33</input>
<input type="checkbox" id="44">我是44</input>
<input type="checkbox" id="55">我是55</input>
</div>
</body>
<script>
function change(){
var year=document.getElementById('year').value;
var checkbox=document.getElementById(year);
checkbox.checked="checked";
}
</script>
</html>