Home > Web Front-end > Layui Tutorial > How to use jquery in layui

How to use jquery in layui

藏色散人
Release: 2020-11-20 10:22:23
Original
4145 people have browsed it

How to use jquery in layui: 1. Actively load the jquery module with statements such as "layui.use(['jquery', 'layer']...)"; 2. Through "layui.use(' layer', function(){...}" method.

How to use jquery in layui

Recommended "layUI Tutorial"

layui uses internal jQuery:

Encountered problem situations:

Because some of Layui’s built-in modules depend on jQuery, jQuery is not introduced separately, but when using $When using the conventional writing method to obtain the dom element, it prompts that it is undefined

Cause of the problem:

Because some of the built-in modules of Layui depend on jQuery, we use the most stable version of jQuery1.11 as a built-in DOM module (the only third-party module). It will be loaded only if the module you use depends on it, and if your page has already introduced jquery via script, it will not be loaded repeatedly. The built-in jquery module Removed the global $ and jQuery, it is a standard module that conforms to the layui specification.

Two solutions:

//第一种:主动加载jquery模块
layui.use(['jquery', 'layer'], function(){ 
  var $ = layui.$ //重点处
  ,layer = layui.layer;
  
  //后面就跟你平时使用jQuery一样
  $('body').append('hello jquery');
});
 
//第二种:如果内置的模块本身是依赖jquery,你无需去use jquery,所以上面的写法其实可以是:
layui.use('layer', function(){ 
  var $ = layui.$ //由于layer弹层依赖jQuery,所以可以直接得到
  ,layer = layui.layer;
 
  //……
});
Copy after login

The above is the detailed content of How to use jquery in layui. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template