
网上一大堆ajax的教程,可以搜一下,慕课网有视频教程,然后再去w3school看下dom替换元素属性,几分钟就搞定了。
基本就是通过dataimage,dataheight等(data是你ajax用来表示接受的数据的变量名)获取数据,然后用dom技术替换img标签的src和alt的值。
<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);
以上就是关于ajax如何循环获取json,赋值到html全部的内容,包括:ajax如何循环获取json,赋值到html、jquery,ajax 如何提交多个checkbox的值、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)