Layui conflict with jquery causes the dropdown box to not display the workaround

Source: Internet
Author: User

1. Background:

When using the Layui framework to write JSPs, use Ajax to pass data to refresh the form, discovering that using AJAX to refer to external jquery and Layui comes with jquery, which could be $ cause the option in the Select drop-down box cannot be in lay Normal use in the UI (that is, the data is passed, but the drop-down box does not have any data)

2. Solve

Check out the solution on the Internet. One workaround is to refer to other jquery before Layui.js . But found that there was no egg to use .

It was later discovered that Ajax passed data after loading the page, causing the imported option not to be rendered at the first time by Layui (and of course the cause of the $ sign conflict).


You need to re-render using Form.render () after updating the form elements.

3. Code

functionLoadcallclass () {$.ajax ({dataType:"JSON",//data type is in JSON formatContentType: "application/x-www-form-urlencoded; Charset=utf-8 ", URL:"ope?method=calllist&id=" + "${userid}" + "",//name of the servlet fileType: "POST", Success:function(data,textstatus) {var$sel = $ ("#classes"); varoptionstring = "";  for(varIinchdata)                        {Console.log ($sel); $item= $ ("<option>" +data[i].claname+ "</option>");//Add Option$item. Val (Data[i].claid);//add option's value$sel. Append ($item);//add option to selectLayui.use ([' Layer ', ' form ',function(){                              varLayer =Layui.layer, Form=Layui.form (); Form.render (' SELECT ');                    });         }                  }             }); } 
View Code

The corresponding body code:

<Bodyonload= "Loadcallclass ()">    <Selectname= "Classes"class= "Layui-input search_input"ID= "Classes">    <optionvalue=""></option>    </Select></Body>
View Code

  

Layui conflict with jquery causes the dropdown box to not display the workaround

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.