81,094
社区成员
发帖
与我相关
我的任务
分享
var reader_magazine = $("reader_magazine");
for ( var i = 0; i < typeAll.length; i++) {
for ( var j = 0; j < typeOne.length; j++) {
if (typeAll[i] == typeOne[j]) {
var checkBox = document.createElement("input");
checkBox.setAttribute("type","checkbox");
checkBox.setAttribute("id", typeOne[j]);
checkBox.setAttribute("name", "typeBox");
reader_magazine.appendChild(checkBox);
}
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'testcheckBoz.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type='text/javascript' src='<%=basePath%>/dwr/engine.js'></script>
<script type='text/javascript' src='<%=basePath%>/dwr/util.js'></script>
<script type="text/javascript">
function getEle(){
var executerDiv = $("executerDiv");
for (var i=0;i<5;i++) {
var checkBox=document.createElement("input");
checkBox.setAttribute("type","checkbox");
checkBox.setAttribute("id",i);
checkBox.setAttribute("name", "typeBox");
checkBox.checked = true;
executerDiv.appendChild(checkBox);
executerDiv.appendChild(document.createTextNode(i));
}
}
function getValue() {
var box = document.getElementsByName("typeBox");
for (var i = 0 ; i < box.length ; i++) {
alert(box[i].id);
if (box[i].checked == true) {
alert("被选中的:" + box[i].id);
}
}
}
</script>
</head>
<body>
<div id="executerDiv"></div>
<input type="button" onclick="getEle()" value="生成checkbox">
<input type="button" onclick="getValue()" value="跳出选中的checkbox">
</body>
</html>