What is the usage of layer.alert in Layui?

The layer.alert function in Layui is utilized to pop up an alert box on the page, informing the user of a certain message.

Here is how to use it:

layer.alert('内容', options, callback);

‘Content’ refers to the text information that needs to be displayed in the alert box.

Options are optional parameters used to set the configuration of the alert box. Commonly used configuration items include:

  1. Icon: Choose an icon to display, options include 0 (default exclamation icon), 1 (checkmark icon), or 2 (error icon).
  2. Title: The default title is set to ‘Prompt’.
  3. Default button settings are set to ‘OK’.
  4. btnAlign: Specify the alignment of the button, defaulting to ‘c’ (center align).
  5. closeBtn: 0 by default (not visible), can be set to show the close button.

The callback is a function that is triggered after clicking the confirm button, allowing for the processing of user actions.

I need to study diligently in order to pass the exam.

I must work hard to pass the exam.

layer.alert('Hello Layui', {icon: 1, title: '提示'}, function(index){
  layer.close(index);  // 点击确定按钮后关闭警告框
});

The code above will display a popup alert on the page with a title and a check icon. The alert box will close when the OK button is clicked.

Please refer to the official documentation of Layui for more configuration options and usage instructions.

bannerAds