后台代码是怎样的
public String findByid() throws Exception {
>我想你理解错了,ajax一半是异步发送连接到后台,
通过动态语言连接数据库读取好数据,以表格的方式组合数据返回到ajax的回调函数里头,直接添加到页面的dom上的
$get("testasp", data:{id:01}, function(data){dataappendTo("div");//将返回的结果添加到页面上})
asp:
<%
id=request("id")
sql="select from tb where
responsewrite("<table>")'这里进行取数据和表格重组,并返回到datd里头
%>客户端提交后,在PHP里面是在$_POST或者$_GET里面,你根据需要保存到session里面即可,具体语句于你form里面的变量有关,例如:
<form method=post>
<select name=chechbox1><option>xxx<option>yyy</select>
</form>
那么,提交后在PHP里面是保存在$_POST里面的,变量为$_POST['checkbox1'],要保存到会话里面,可以这样:
$SESSION['form_checkbox1']=$_POST['checkbox1'];
变量名都是由你喜欢取的。
<input type="checkbox" name="student" value="1" data-age="18" />
<input type="checkbox" name="student" value="2" data-age="19" />
<input type="checkbox" name="student" value="3" data-age="20" />
var student = $("input[name='student']:checked")serialize();
$ajax({
url: "your-url",
type: "post",
data: student,
success: function (result) {
//handle
}
});
如果3个都是选中的状态的话,后台接收的数据为1,2,3
扩展资料:
关于jQuery对checkbox的其他 *** 作
1、根据id获取checkbox
$("#cbCheckbox1");
2、获取所有的checkbox
$("input[type='checkbox']");//or
$("input[name='cb']");
3、获取所有选中的checkbox
$("input:checkbox:checked");//or
$("input:[type='checkbox']:checked");//or
$("input[type='checkbox']:checked");//or
$("input:[name='ck']:checked");
4、获取checkbox值
//用val()即可,比如:
$("#cbCheckbox1")val();
5、获取多个选中的checkbox值
var vals = [];
$('input:checkbox:checked')each(function (index, item) {
valspush($(this)val());
});
6、判断checkbox是否选中(jquery 16以前版本 用 $(this)attr("checked"))
$("#cbCheckbox1")click(function () {
if ($(this)prop("checked")) {
alert("选中");
} else {
alert("没有选中");
}
});
7、设置checkbox为选中状态
$('input:checkbox')attr("checked", 'checked');//or
$('input:checkbox')attr("checked", true);
8、设置checkbox为不选中状态
$('input:checkbox')attr("checked", '');//or
$('input:checkbox')attr("checked", false);
9、设置checkbox为禁用状态(jquery<16用attr,jquery>=16建议用prop)
$("input[type='checkbox']")attr("disabled", "disabled");//or
$("input[type='checkbox']")attr("disabled", true);//or
$("input[type='checkbox']")prop("disabled", true);//or
$("input[type='checkbox']")prop("disabled", "disabled");
10、设置checkbox为启用状态(jquery<16用attr,jquery>=16建议用prop)
$("input[type='checkbox']")removeAttr("disabled");//or
$("input[type='checkbox']")attr("disabled", false);//or
$("input[type='checkbox']")prop("disabled", "");//or
$("input[type='checkbox']")prop("disabled", false);
我们做这种复选框,都是绑定一个实体参数,把每个选项的值设为0,1,2,3,对应的汉字是“体育”“音乐”“”“其他”。以拼接字符串的形式存入数据库,如:1,2 表示体育、音乐被选中。js代码:
$("#button")click(function(){var value1 = $("#name")val();
alert(value1);
$("#name")val("修改了值")
var value2 = $("#name")val();
alert(value2);
});
输出结果第一个警告框:执行后台取的值
输出结果第一个警告框:修改了值
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)