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.
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; //…… });
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.