jq设置checkbox默认选中状态

1.后台发送的数据 是spring框架中的对象model.addObject(“student”,stu);
前台页面由隐藏的接收对象

页面代码:

id="wfsi" class="hidden" th:value="${student.age}"/>

<div>
id="ckbx" type="checkbox"/>
div>

jq代码设置checkbox的几种方式:

1.attr
//设置复选框为勾选状态
$("#ckbx").attr("checked","checked");

//设置复选框未选中状态
$("#ckbx").removeAttr("checked");

2.prop
//设置复选框为勾选状态
$("#ckbx").prop("checked",true);

以上是在jq.1.12.4.js和bootstrap环境下运行,具体行为是前端html页面发送请求到controller,springBoot自动获取对应的数据进行处理,将返回的结果对象(Model以及addObject方法)传回给html,然后jq获取负责接收数据的input标签的值。

你可能感兴趣的:(jq设置checkbox默认选中状态)