JS alert 封装callback
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<script src="js/jq.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<script type="text/javascript">
var funcs = {
show: function(params, callback) {
var html = "";
html += "<div><h1>" + params.title + "</h1><button class='determine'>" + params.ok + "</button><button>" + params.cancel + "</button></div>";
$("body").append(html);
$("body").on("click", ".determine", function() {
callback("点击确定");
});
},
_alert: function(message, title, callback) {
if(title == null) title = '提示';
funcs.show({
title,
message,
type: 'alert'
}, function(result) {
if(callback && callback instanceof Function) {
callback(result)
}
});
},
}
funcs.show({
title: "标题",
ok: "确定",
cancel: "取消",
type: 'alert'
}, function(res) {
console.log(res)
})
</script>
</body>
</html>