mui消息框(alert,confirm,prompt,toast)的使用
在开发mui的过程中,我们最经常用到的就是消息框,例如警告框、确认框、对话框、消息提示框等等一系列的弹出消息框。mui没有让我们失望,这些都做好了封装
alert(警告框)
用法:.alert( message, title, btnValue, callback [, type] )
message
Type: String
提示对话框上显示的内容
title
Type: String
提示对话框上显示的标题
btnValue
Type: String
提示对话框上按钮显示的内容
callback
Type: String
提示对话框上关闭后的回调函数
type
Value: ‘div’
是否使用h5绘制的对话框
示例代码:html:
<button id='alertBtn' type="button" class="mui-btn mui-btn-blue mui-btn-outlined">警告消息框</button>
<div id="info"></div>
js:
var info = document.getElementById("info");
document.getElementById("alertBtn").addEventListener('tap', function() {
mui.alert('欢迎使用Hello MUI', 'Hello MUI', function() {
info.innerText = '你刚关闭了警告框';
});
});
confirm(确认框)
用法:.confirm( message, title, btnValue, callback [, type] )
message
Type: String
提示对话框上显示的内容
title
Type: String
提示对话框上显示的标题
btnValue
Type: String
提示对话框上按钮显示的内容
callback
Type: String
提示对话框上关闭后的回调函数
type
Value: ‘div’
是否使用h5绘制的对话框
示例代码:html:
<button id='confirmBtn' type="button" class="mui-btn mui-btn-blue mui-btn-outlined">确认消息框</button>
<div id="info"></div>
js:
var info = document.getElementById("info");
document.getElementById("confirmBtn").addEventListener('tap', function() {
var btnArray = ['否', '是'];
mui.confirm('MUI是个好框架,确认?', 'Hello MUI', btnArray, function(e) {
if (e.index == 1) {
info.innerText = '你刚确认MUI是个好框架';
} else {
info.innerText = 'MUI没有得到你的认可,继续加油'
}
})
});
prompt(对话框)
用法:.prompt( message, placeholder, title, btnValue, callback[, type] )
message
Type: String
提示对话框上显示的内容
placeholder
Type: String
编辑框显示的提示文字
title
Type: String
提示对话框上显示的标题
btnValue
Type: String
提示对话框上按钮显示的内容
callback
Type: String
提示对话框上关闭后的回调函数
type
Value: ‘div’
是否使用h5绘制的对话框
示例代码:html:
<button id='promptBtn' type="button" class="mui-btn mui-btn-blue mui-btn-outlined">输入对话框</button>
<div id="info"></div>
js:
var info = document.getElementById("info");
document.getElementById("promptBtn").addEventListener('tap', function(e) {
e.detail.gesture.preventDefault(); //修复iOS 8.x平台存在的bug,使用plus.nativeUI.prompt会造成输入法闪一下又没了
var btnArray = ['取消', '确定'];
mui.prompt('请输入你对MUI的评语:', '性能好', 'Hello MUI', btnArray, function(e) {
if (e.index == 1) {
info.innerText = '谢谢你的评语:' + e.value;
} else {
info.innerText = '你点了取消按钮';
}
})
});
toast(消息提示框)
用法:.toast( message [,options])
message
Type: String
提示对话框上显示的内容
options
Type: JSON
提示消息的参数
示例代码:html:
<button id='toastBtn' type="button" class="mui-btn mui-btn-blue mui-btn-outlined">自动消失提示框</button>
<div id="info"></div>
js:
var info = document.getElementById("info");
document.getElementById("toastBtn").addEventListener('tap', function() {
mui.toast('欢迎体验Hello MUI');
});
这些提示框的内容你可以自己使用标签代码来布局你想要提示的展现样子,可以自定义样式,具体代码如下:
我们拿confirm这个方法来举例说明下(其余方法都和这个一样):
html代码还是之前那个一样。
js:
var info = document.getElementById("info");
document.getElementById("confirmBtn").addEventListener('tap', function() {
var btnArray = ['否', '是'];
var message = '<h6>MUI是个好框架,确认?</h6>';
mui.confirm(message, 'Hello MUI', btnArray, function(e) {
if (e.index == 1) {
info.innerText = '你刚确认MUI是个好框架';
} else {
info.innerText = 'MUI没有得到你的认可,继续加油'
}
},'div');
});
mui消息框(alert,confirm,prompt,toast)的使用
转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
confirm,alert,prompt
confirm,alert,prompt的基本用法
职场 休闲 prompt alert confirm -
js:常用的3种弹出提示框(alert、confirm、prompt)
函数定义function alert(message?: any): voidfunction confirm(message?:
javascript 前端 开发语言 提示框 函数定义 -
js中的弹窗alert、confirm和prompt
ndow 对象位于对象层次的顶层,因此实际应用中不必使用这些消息框的全名(例如 "window.alert
js弹窗 JavaScript alert confirm prompt -
window对象属性alert、confirm、prompt怎么使用?
window对象属性alert、confirm、prompt怎么使用? 一、总结 1、参数
BOM window对象 微信 人工智能 css