jquery gets some properties of the CheckBox check state in the specified element

Source: Internet
Author: User

Project users upload case data, each upload automatically generated a case folder, data saved to the background, the front-end display folder, now the need is to check the folder you want to delete the Chenckbox, click Delete, the database and the front end are updated accordingly.

if it is a static page, navigate directly to the checkbox based on the ID or class, then determine the status, Remove directly. But the dynamic page, needs to synchronize with the background, the front-end corresponding folder deletion, the background database also to delete the data within the folder, each case folder corresponds to a database of RecordID, then the problem is, How to know the case ID of the folder selected in the current checkbox (the folder is generated dynamically, if the number of folders is fixed, directly according to the method of static pages to get it), the project is to use the Flask framework, see:

1 <ulclass= "Divall">2 {%for record in records%}3 {%if current_user==user%}4   <Liclass= "Pat_li">5      <inputtype= "text"class= "Pat"value= "{{record.title}}"onfocus= "rename (this)"onblur= "Blur_supervise (this)"ReadOnly/>6      <Buttonclass= "Btn_name_ok glyphicon glyphicon-ok"onclick= "Ok_name ()"></Button>7      <Buttonclass= "Btn_name_remove glyphicon glyphicon-remove"onclick= "Remove_name (this)"></Button>8          <ulclass= "Pat_assist">9             <Li><inputtype= "button"class= "Btn_img_icon"  > <imgID={{record.id}}src={{ url_for (' static ', filename= ' images/dia_mng/delete_icon.png ')}} onclick=del_record (This)></input></Li>Ten             <Li><ahref= "{{url_for (' main.history_list ', Type=dia_type,record_id=record.id)}}"><Buttonclass= "Btn_img_icon"><imgsrc={{ url_for (' static ', filename= ' images/dia_mng/icon_hiy.png ')}}></Button></a></Li> One             <Li> <ahref= "{{url_for (' main.record_diagnosis ', Record_id=record.id,record_type=dia_type)}}"><Buttonclass= "Btn_img_icon"><imgsrc={{ url_for (' static ', filename= ' images/dia_mng/icon_dia.png ')}}></Button></a></Li> A          </ul> -          <inputtype= "checkbox"class= "Chkfolder"> -            <ahref= "{{url_for (' main.record_diagnosis ', Record_id=record.id,record_type=dia_type)}}"></a> the           </Li> - {% endif%} - {% endfor%} -    </ul>

The code, line 2nd, line 3 is the Flask Loop statement, which means to cycle the generation of <li> tags based on the length of the case ID of the database .... The LI tag wraps a template for a folder, so how to determine the checkbox that is currently checked on line 13th, The corresponding case ID to delete the backend database? The workaround is to modify the code:

<type= "checkbox"  class= "Chkfolder"  ID={{ Record.id}}>

Assign the record ID of each item in the record in records to the id attribute of input, then iterate through all the elements selected by the checkbox as true, get the id attribute, put in the array, the case ID array, and then pass Ajax to the background refresh page:

 1  var  channel=[]; 
All selected elements of type checkbox within the//divall 2 var a=$ ('. Divall Input[type=checkbox]: Checked '). each (function () 3 {//Get ID join array 4 if ($.inarray (JQuery (this ). attr ("id"), channel) ==-1 5 channel.push (jQuery (this "). attr ("id" 6 } 7 });

The checkbox's property is True or FALSE, but the value obtained by Jqure for true is checked. The ID is obtained and then passed to the background via Ajax.

 varRecord_check = {         "RECORDS_ID": Channel,"Dia_type": "{{dia_type}}",} $.ajax ({type:"POST", URL:"/delete_records", Data:JSON.stringify (Record_check), DataType:' JSON ', ContentType:"Application/json; Charset=utf-8 ", Success:function(data) {Console.log (Data.flag); if(data.flag==1) window.location.reload (); Else{alert ("The deletion was unsuccessful, please select Delete Case"); }                     }                 });

jquery gets some properties of the CheckBox check state in the specified element

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.