layer.prompt 增長placeholder 提示

爲layer.prompt增長輸入框提示javascript

 

打開 layer.js,用搜索工具找到prompt一行代碼,下圖爲修改之後的:java

注:原代碼的單引號和雙引號的使用工具

這是用格式化工具格式化了ui

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 class="layui-layer-input"' + a + ' placeholder="' + (e.placeholder?e.placeholder:'') + '"></textarea>': function() {
        return '<input type="' + (1 == e.formType ? 'password': 'text') + '" placeholder="' + (e.placeholder?e.placeholder:'') + '" class="layui-layer-input">'
    } (),
    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))
},

 引用方法:spa

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);
});

  

效果:orm

相關文章
相關標籤/搜索