為layer.prompt增加輸入框提示
打開 layer.js,用搜索工具找到prompt一行代碼,下圖為修改以后的:

注:原代碼的單引號和雙引號的使用
這是用格式化工具格式化了
r.prompt = function(e, t) {
var a = "";
if (e = e || {},
"function" == typeof e && (t = e), e.area) {
var o = e.area;
a = 'style="width: ' + o[0] + "; height: " + o[1] + ';"',
delete e.area
}
var s, l = 2 == e.formType ? '<textarea ' + a + ' placeholder="' + (e.placeholder?e.placeholder:'') + '"></textarea>': function() {
return '<input type="' + (1 == e.formType ? 'password': 'text') + '" placeholder="' + (e.placeholder?e.placeholder:'') + '" >'
} (),
f = e.success;
return delete e.success,
r.open(i.extend({
type: 1,
btn: ["確定", "取消"],
content: l,
skin: "layui-layer-prompt" + c("prompt"),
maxWidth: n.width(),
success: function(t) {
s = t.find(".layui-layer-input"),
s.val(e.value || "").focus(),
"function" == typeof f && f(t)
},
resize: !1,
yes: function(i) {
var n = s.val();
"" === n ? s.focus() : n.length > (e.maxlength || 500) ? r.tips("最多輸入" + (e.maxlength || 500) + "個字數", s, {
tips: 1
}) : t && t(n, i, s)
}
},
e))
},
參考方法:
layer.prompt({
formType: 0, //輸入框型別,支持0(文本)默認1(密碼)2(多行文本)
maxlength: 12, //限制長度
value: '', //初始時的值,默認空字符
title: '標題', //標題
placeholder: '提示資訊', //提示資訊,默認空字符
area: ['400px', '22px']//自定義文本域寬高
}, function(value, index){
console.log(value,index);
layer.close(index);
});
效果:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/235689.html
標籤:jQuery
上一篇:第四章 變數、函式和運算子
