html:
<code><ul class="box2" sss="a"> <div> <input class="input checkboxs" aa="001" type="checkbox"><span> 一</span> </div> <div> <input class="input checkboxs" aa="002" type="checkbox"><span> 二</span> </div> </ul> <ul class="box2" sss="b"> <div> <input class="input checkboxs" aa="001" type="checkbox"><span> 三</span> </div> <div> <input class="input checkboxs" aa="002" type="checkbox"><span> 四</span> </div> </ul></code>
sss represents the area, and a session is generated when the checkbox is clicked, like this: $_SESSION [$sss] [$aa].
The requirement is: when the page is refreshed, the checked items are still checked.
I know that I can set an ID for the checkbox, and it will be checked by default based on the ID setting. It also worked, but mainly I wanted to know how many he checked in area a or b. So I use a 2D array.
This is the controller under the jQuery and CI framework that I use the id setting to be checked by default.
jQuery:
<code>var checks=$('input:checkbox'); for(var i=0;i<checks.length;i++){ //将checkbox的id传过去比较,返回存在的id $.post('is_session',{checkid:checks[i].id},function(data){ //存在则默认被选中 //alert(data); $('#'+data).attr('checked',true); }); }</code>
CI:
<code>public function is_session(){ //当点击选项时 将所属id传过来 $checked=$this->input->post('checkid'); //$area=$this->input->post('area'); //判断$_SESSION[$checked],若存在返回$checked(id) if(!empty($_SESSION[$checked])){ echo $checked; } } </code>
html:
<code><ul class="box2" sss="a"> <div> <input class="input checkboxs" aa="001" type="checkbox"><span> 一</span> </div> <div> <input class="input checkboxs" aa="002" type="checkbox"><span> 二</span> </div> </ul> <ul class="box2" sss="b"> <div> <input class="input checkboxs" aa="001" type="checkbox"><span> 三</span> </div> <div> <input class="input checkboxs" aa="002" type="checkbox"><span> 四</span> </div> </ul></code>
sss represents the area, and a session is generated when the checkbox is clicked, like this: $_SESSION [$sss] [$aa].
The requirement is: when the page is refreshed, the checked items are still checked.
I know that I can set an ID for the checkbox, and it will be checked by default based on the ID setting. It also worked, but mainly I wanted to know how many he checked in area a or b. So I use 2D array.
This is the controller under the jQuery and CI framework that I use the id setting to be checked by default.
jQuery:
<code>var checks=$('input:checkbox'); for(var i=0;i<checks.length;i++){ //将checkbox的id传过去比较,返回存在的id $.post('is_session',{checkid:checks[i].id},function(data){ //存在则默认被选中 //alert(data); $('#'+data).attr('checked',true); }); }</code>
CI:
<code>public function is_session(){ //当点击选项时 将所属id传过来 $checked=$this->input->post('checkid'); //$area=$this->input->post('area'); //判断$_SESSION[$checked],若存在返回$checked(id) if(!empty($_SESSION[$checked])){ echo $checked; } } </code>
I feel like your idea is wrong
I recommend you a method
$(obj).load("url #local refresh id");
Use jquery for partial refresh, and attach the corresponding attributes during the loop