[JSP] layui + jsp, according to background information check box is checked by default

1. The projects often use check boxes, when repeated loading, it needs to box a default value from the database.

2. Next, using the method of iterations in JSP, check boxes to bind values. Ideas and methods is not necessarily good for reference purposes only.

<input type="checkbox" class="layui-form-checkbox" id="${menu.menu_code}" value="${menu.menu_id}" lay-skin="primary" data-id='${menu.menu_id}'/></td>

I use the input tag checkbox, check box.

Input is used to hook the bonding id methods.

<C: forEach var = "Model" items = "$ {} maps.menuData" varStatus = "varStatusName"> 
         var . $ code = ( "$ {#} model.menu_code") prop ( "the checked", to true ); // to check the checkbox of 
       the console.log (model.menu_code $ {});
 </ C: forEach> // use the JSTL jsp standard library, the package may need to import 
// the foreach loop similar to the recycling prop menu_code method 
// to bind checked for input method

Above <c: forEach> iterative basis label to receive the plurality of collection type.

That cycle id, input box to hook the binding method.

The following is the complete code js

<script>
    $(function() {

        <c:forEach var="model" items="${maps.menuData}" varStatus="varStatusName">
        var code=$("#${model.menu_code}").prop("checked",true); //给复选框打勾
       console.log(${model.menu_code});
        </c:forEach>
        });

        layui.use(["jquery", "upload", "form", "layer", "element"], function () {
            var $ = layui.$,
                element = layui.element,
                layer = layui.layer,
                upload = Layui.upload, 
                form = layui.form;
           // custom validation rules 
          form.verify ({ 
            nikename: function (value) {
               IF (value.length <. 5 ) {
                 return 'nickname ah characters have at least 5' ; 
              } 
            } 
            , hours: [ / ^ [0-9_ \ u4e00- \ \\ u9fa5 · S] + $ /, 'number of digits only hours' ] 
          }); 


 
    / *         form.on ( 'SELECT (roleName)', function (Data) { 
                var Grade = data.value; 
                var = document.getElementById code ( "role_code"); 
                code.value = Grade; 
 ! / * the console.log (data.elem); // get select original DOM object * /! 
             the console.log (data.value); // get the selected value 
 / * console.log! (data.othis); // get DOM object beautified * /! 
            }); 
the note is to monitor the drop-down box roleName, check to role_code binding value
* / // listening to submit form.on ( 'submit (add) ', function (Data) { // Get all input tag var input = document.getElementsByTagName ( "input" ); var STR = "" ; for ( var I = 0; I <input.Length; I ++ ) { var obj =INPUT [I]; // determines whether the checkbox has been checked and IF (obj.type == "checkbox" && obj.checked) { var code = obj.value; // Get the value of the checkbox str = str + code + ", " ; } } the console.log (STR); var role_code = $ ( '# role_code' ) .val (); var role_menu = { ROLE_ID: role_code, menu_id: STR }; $ .ajax ({ URL:,"/ The CMS / Role_Menu / AddRole_Menu" type: "POST" , Data: role_menu, Success: function (RES) { IF (RES == 'to true' ) { layer.alert ( "increase the success", icon {:}. 6, function () { // get frame index window.parent.location.reload (); var index = parent.layer.getFrameIndex (the window.name); // Close the current Frame parent.layer.close (index); window.location.reload (); }); } the else { layer.msg ( 'addition failed', {icon:. 6 }); } } }); return to false ; }); }); </ Script>

 

Use get all the input and then screened using the method selected in the box is sent to the background value

 

 

Guess you like

Origin www.cnblogs.com/suncos/p/11828555.html
jsp