current position:Home>Layui framework application FAQ

Layui framework application FAQ

2022-04-29 14:19:54Programming essay LayUI Frame document home page

obtain URL Parameters

Such as in a table “ edit ”,“ details ” Tool button , You need to get in the pop-up layer page URL Parameters passed in .

function getQueryString(name) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    let r =;
    if (r != null) {
        return decodeURIComponent(r[2]);
    return null;

Refresh table data when closing pop-up layer

stay Add a callback function in :end: function().

//  Process... In table rows “ edit ” Pop up layer close callback 
table.on('tool(demoTableFilter)', function (obj) {
    var data =;
    if (obj.event === 'edit') {
        var index ={
            title: ' edit ',
            type: 2,
            shade: 0.2,
            shadeClose: true,
            area: ['100%', '100%'],
            content: '../page/table/edit.html?id=', //  Pass on URL Parameters 
            end: function(){
                //  Refresh the table when closing the pop-up layer 
        $(window).on("resize", function () {
        return false;

Set the default option value of the drop-down box

// According to the value option Choose  
$("#mySelect option[value='"+myValue+"']").attr("selected","selected"); 

The drop-down box is dynamically assigned through the interface

Page elements :

<select name="mySelect" id="mySelect" lay-verify="required" lay-filter="xxxFilter">
<option value=""></option>

Request dynamic assignment of interface data :

    url: '/xxx/data/list',
    dataType: 'json',
    type: 'get',
    success: function (data) {
        $.each(data, function (index, item) {
            //  Dynamically add elements to the drop-down menu 
            $('#mySelect').append(new Option(item.xm,; 
        //  To render , This operation is very important 
        //  If you need to set the default options of the drop-down box , Must be performed before this operation 
        //  Set the default selection of the drop-down menu 
        // $("#mySelect option[value='"+myValue+"']").attr("selected","selected"); 

【 Reference resources 】 layui Pop up layer close callback js obtain url Several ways of parameter value layui modify select The value of the method LAYUI Drop down box background dynamic assignment

copyright notice
author[Programming essay],Please bring the original link to reprint, thank you.

Random recommended