1. java中保存复选框的值,插入到数据库中用哪种方法详细点给分!!!
<head>
<script type="text/javaScript">
function getValue(){
var box= document.getElementsByName("checkBox1");
var boxValue="";
for(var i=0;i<box.length;i++){
if(box[i].checked==true){
boxValue+=box[i].value+"#";//将选中的值累加
}
}
document.getElementById("setValue").value=boxValue;//将选中的值赋给hidden,方便在后台取出
}
</script>
</head>
<body>
<input type="checkBox" name="checkBox1" value="1"/>
<input type="checkBox" name="checkBox1" value="2"/>
<input type="checkBox" name="checkBox1" value="3"/>
<input type="checkBox" name="checkBox1" value="4"/>
<input type="hidden" id="setValue" name="vlaue"/>
<input type="button" value="提交" onclick="getValue();"/>
</body>
在后台
String[] string = request.getParameter("value").split("#");
for(int i=0;i<string.length;i++){
System.out.println(string[i]);//string[i]就是页面中被选中的值
}
其实这是一种比较笨的方法,不过胜在通用。
2. php中复选框转成字符串存到数据库,然后怎么展示到表格,源生代码
先声明我也是一名小白(或者说是“PHP爱好者”)//以下内容仅供参考
经过多次分析可以用这几种方案:
一、把复选内容写入配置文件(参考dedecms的数据库)
二、把复选内容写入数据库,使用时只需要在加载系统时把配置内容加载然后就可以在任意位置使用。
3. 怎样把checkbox选中的值添加到数据库中啊能给一点代码吗
简单例子,你在aspx页面上放上这个
你喜欢的食物<br/>
<input type="checkbox" name="chbFood" value="apple" />苹果<br/>
<input type="checkbox" name="chbFood" value="orange" />橘子<br/>
<input type="checkbox" name="chbFood" value="banana" />香蕉<br/>
<input type="checkbox" name="chbFood" value="bread" />面包<br/>
<asp:Button runat="server" Text="提交" ID="btnSubmit"/>
在接收数据的页面的cs文件的Page_Lode里面放上这个
object obj=Request.Form["chbFood"];
if (obj != null)
{
string strFood = (string)obj;
Response.Write(strFood);
}
当你做了选择,点击提交,就会在页面上输出你选中的项的value。