我想做个Checkbox树,然后把Checkbox选种的值传如数据库,请问斑竹有什么好的方法啊?
Checkbox的树也从数据库中读出相应的数据,我是用个控件实现的,但是由于控件的方法没有传值,所以不知道怎么样把选中的数据传值并存如数据库中,帮忙想想好吗?代码如下,导入的JS文件已上传
<%@ page contentType="text/html; charset=GBK" import="java.lang.String"%>
<jsp:useBean id="db" scope="page" class="system.dbconnection"/>
<%@ page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<script src="alai_win_xp.js"></script>
<script src="alai_tree.js"></script>
<script src="alai_tree_pretty.js"></script>
<script src="alai_tree_check.js"></script>
</head>
<body>
<p> </p>
<div id="divTree1"></div>
<p align="center"> </p>
<script>
var tree1=new alai_tree_pretty(divTree1)
var root=tree1.root
<%
String str[]=new String[6];
int i=0;
ResultSet result;
Statement stmt=null;
String sql="select * from qx";
Connection con=db.getConnection();
stmt=con.createStatement();
result=stmt.executeQuery(sql);
while(result.next())
{
if(result.getString("flag").equals("add")){
str[i]="var "+result.getString("code")+"="+result.getString("parcode")+"."+result.getString("flag")+"(\""+result.getString("name")+"\")";
i++;
}
else{
str[i]="tree1.addChkNode("+result.getString("parcode")+",\""+result.getString("name")+"\")";
i++;
}
}
for(int n=0 ; n < str.length ; n++)
{
out.println(str[n]);
}
%>
tree1.oncheck=function(srcNode)
{
if(srcNode.checkBox.checked) //添加
{
var item=document.createElement("option")
item.text=item.value=srcNode.label.innerText
}else //取消
{
for(var i=0;i<sltName.options.length;i++)
{
if(srcNode.label.innerText==sltName.options[i].value)sltName.options[i]=null;
}
}
}
n11.checkBox.checked=n12.checkBox.checked=n13.checkBox.checked=true
/*程序代码浏览窗口*/
var script=document.getElementsByTagName("SCRIPT")
var sCode=script[4].innerHTML
sCode=sCode.replace(/</g,"<").replace(/>/g,">")
sCode=sCode.replace(/([A-Za-z0-9><_\)\(\]\[\}\{\. \$/;=\+\?"&:-]{2,})/g,"<font color='green'>$1</font>");
sCode=sCode.replace(/\t/g," ")
sCode=sCode.replace(/(\/\*)/g,"<font color='maroon'>$1")
sCode=sCode.replace(/(\*\/)/g,"$1</font>")
sCode=sCode.replace(/\n/g,"<br>")
winCode=new alai_win_xp(sCode,"程序代码浏览窗口",600,500,45,120)
winCode.addButton("隐藏","hide")
winCode.content.style.cssText="text-align:left;color:darkblue;background-color:#dddddd"
/* The End */
</script>
</body>
</html>
数据库和JAVABEAN请斑竹随便写个测试下,小弟不明白的主要是JS的问题,所以将帖子发在次论坛中......
<SCRIPT src=\"alai_win_xp.js\">