Several writing methods in js: The first writing, record, and js writing

Source: Internet
Author: User

Several writing methods in js: The first writing, record, and js writing

--- Restore content start ---

1. jsp page style

<Div class = "row cl">
<Label class = "form-label col-xs-4 col-sm-2" style = "text-align: right;"> vehicle properties: </label>
<Div class = "formControls col-xs-8">
<Dl class = "permission-list"> <input type = "checkbox" value = "" name = "user-Character-0" id = "checkAll"

    

// Compare the length of two lists on the jsp page: $ {fn: length (list1) = fn: length (list2 )}, use fn to introduce <% @ taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions" %> On the page

<C: if test = "$ {fn: length (autobasic. autoattributeList) = fn: length (autobasic. automappingattrList)} "> checked =" checked "</c: if>
>Select All:</Label>

</Dt>
<Dd>
<C: forEach items = "$ {autobasic. autoattributeList}" var = "autoattribute" varStatus = "status">
<Label class = "attrcheboxclass">

// Add another foreach loop traversal to the input to determine whether each checkbox is selected. if selected, add the checked attribute to the input.
<Input type = "checkbox" class = "checkOne" name = "checkbox_name" value = "$ {autoattribute. autoattributeId }"
<C: forEach items = "$ {autobasic. automappingattrList}" var = "automappingattr">
<C: if test = "$ {automappingattr. autoattributeId = autoattribute. autoattributeId}"> checked = "checked" </c: if>
</C: forEach>
>
$ {Autoattribute. name} </label>
</C: forEach>
</Dd>
</Dl>
</Div>
</Div>

Effect

 

2. Get the value in the check box

Var idStr = "";
$ ("Input [name = 'checkbox _ name']"). each (function (){
If ($ (this). is (": checked ")){

// Separate the strings with commas (,). Separate the values after being uploaded to the background.
IdStr + = $ (this). val () + ",";
}
});
Entity. temporary = idStr;

The following is the background code:

String [] strs = autobasic. getTemporary (). split (",");

For (int I = 0; I <strs. length; I ++ ){
Temp. setAutoattributeId (Integer. parseInt (strs [I]);

Save to the corresponding database
This. automappingattrService. insert (temp, "Automappingattr ");
}

3. Select All and select none in js:

CheckAll is the id of the all-selected box.

$ ("# CheckAll"). click (function (){

When the attribute of the all-selected box is changed to the checked attribute, all the checkbox with name as checkbox_name is traversed once and selected. prop is used here.
If ($ (this). is (': checked ')){
$ ("Input [name = 'checkbox _ name']"). each (function (){
$ (This). prop ("checked", true );
});

When the checked option is set to false, all the checkboxes with the name checkbox_name are traversed cyclically once, and none of them are selected.
} Else {
$ ("Input [name = 'checkbox _ name']"). each (function (){
$ (This). prop ("checked", false );
});
}
});

When the checkBox box is clicked, traverse all single partitions whose names are checkbox_name. If all single partitions are selected, the All selected boxes are also selected.
$ ("Input [name = 'checkbox _ name']"). click (function (){
Var flag = true;
$ ("Input [name = 'checkbox _ name']"). each (function (){
If (! $ (This). is (": checked ")){
Flag = false;
}
});
If (flag = true ){
$ ("# CheckAll"). prop ("checked", true );
} Else {
$ ("# CheckAll"). prop ("checked", false );
}
});

 

--- Restore content end ---

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.