jsp代码哪里出错了?想做一个动态生成CheckBox的代码
<head><metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"><title>利用者情报入力画...
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>利用者情报入力画面</title>
<script src="./plugins/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(function(){
var interestsValues=['TableTennis','Basketball'];
var interests="";
for(var i=0;i<interestsValues.length;i++){
interests += '<input type="checkbox"/><label>'+interestsValues[i]+'<label>';
}
$("#checkedbox").append(interests);
}
</script>
</head>
<body>
<p>
趣味:
</p>
<div id="checkedbox"></div>
<input type="reset" name="reset" value = "返回"/>
<input type="button" name="login" value = "确认"
onclick="window.location.href='JSP/kunin.jsp'" />
</form>
</body> 展开
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>利用者情报入力画面</title>
<script src="./plugins/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(function(){
var interestsValues=['TableTennis','Basketball'];
var interests="";
for(var i=0;i<interestsValues.length;i++){
interests += '<input type="checkbox"/><label>'+interestsValues[i]+'<label>';
}
$("#checkedbox").append(interests);
}
</script>
</head>
<body>
<p>
趣味:
</p>
<div id="checkedbox"></div>
<input type="reset" name="reset" value = "返回"/>
<input type="button" name="login" value = "确认"
onclick="window.location.href='JSP/kunin.jsp'" />
</form>
</body> 展开
1个回答
展开全部
几个问题
第一个问题$()没闭合。
$(function () {
var interestsValues = ['TableTennis', 'Basketball'];
var interests = "";
for (var i = 0; i < interestsValues.length; i++) {
interests += '<label><input type="checkbox"/>' + interestsValues[i] + '<label>';
}
$("#checkedbox").append(interests);
})
第二个问题,DOM未加载完成就可以操作DOM
$(document).ready(function() {
var interestsValues = ['TableTennis', 'Basketball'];
var interests = "";
for (var i = 0; i < interestsValues.length; i++) {
interests += '<label><input type="checkbox"/>' + interestsValues[i] + '<label>';
}
$("#checkedbox").append(interests);
})
或者把js放在</body>结束标签前面,来确保DOM已加载完成
<p>
趣味:
</p>
<div id="checkedbox"></div>
<input type="reset" name="reset" value="返回" />
<input type="button" name="login" value="确认" onclick="window.location.href='JSP/kunin.jsp'" />
<script>
$(document).ready(function() {
var interestsValues = ['TableTennis', 'Basketball'];
var interests = "";
for (var i = 0; i < interestsValues.length; i++) {
interests += '<label><input type="checkbox"/>' + interestsValues[i] + '<label>';
}
$("#checkedbox").append(interests);
})
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询