2.0.0 • Published 2 years ago

cxdialog v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

cxDialog

cxDialog 是基于 JavaScript 的对话框插件,支持自定义外观样式。

Demo: https://ciaoca.github.io/cxDialog/

从 v2.0 开始,已移除 jQuery 的依赖,如果需要使用旧版,可查看 v1 分支

安装方法

浏览器端引入

<link rel="stylesheet" href="cxdialog.css">
<script src="cxdialog.js"></script>

从 NPM 安装,作为模块引入

npm install cxdialog
import 'cxdialog.css';
import cxDialog from 'cxdialog';

使用

// 简易的方式
cxDialog('内容');

cxDialog('内容', () => {
  // click ok callback
}, () => {
  // click no callback
});

// 传入参数
cxDialog({
  title: '标题',
  info: '内容',
  ok: () => {},
  no: () => {}
});

设置默认参数

cxDialog.defaults.title = '提示';

参数说明

名称类型默认值说明
titlestring''标题
infostringelement''内容,可设置为文本内容,或 DOM 元素
okfunctionundefined确认按钮回调函数※ 值为 function 类型时,才会显示对应按钮
nofunctionundefined取消按钮回调函数
okTextstring'确 定'确认按钮文字
noTextstring'取 消'取消按钮文字
buttonsarray[]自定义按钮
baseClassstring''追加样式名称,不会覆盖默认的 class
maskClosebooleantrue是否允许点击遮罩层关闭对话框

buttons 参数

cxDialog({
  info: '内容',
  buttons: [
    {
      text:'按钮1',
      callback: () => {}
    },
    {
      text:'按钮2',
      callback: () => {}
    }
  ]
});
名称类型说明
textstring按钮文字
callbackfunction回调函数

API 接口

cxDialog.close();
名称说明
close关闭对话框