diff --git a/docs/layer/index.md b/docs/layer/index.md index 6f463e50..ae5edf22 100644 --- a/docs/layer/index.md +++ b/docs/layer/index.md @@ -210,7 +210,7 @@ layer.tips('显示在目标元素上方', '#id', { | 私有属性 | 描述 | 类型 | 默认值 | | --- | --- | --- | --- | -| formType | 输入框类型。支持以下可选值: | number | `0` | +| formType | 输入框类型。支持以下可选值: | number/string | `0` | | value | 输入框初始值 | string | - | | maxlength | 可输入的最大字符长度 | number | `500` | | placeholder | 输入框内容为空时的占位符 | string | - | diff --git a/src/modules/layer.js b/src/modules/layer.js index 2f8a592b..699ff95c 100644 --- a/src/modules/layer.js +++ b/src/modules/layer.js @@ -1505,9 +1505,21 @@ var skin = function(type){ // 仿系统 prompt layer.prompt = function(options, yes){ - var style = '', placeholder = ''; + var style = ''; + var placeholder = ''; options = options || {}; + // 兼容旧版参数 + var legacyTypeMap = { + 0: 'text', + 1: 'password', + 2: 'textarea' + }; + if(options.formType in legacyTypeMap){ + options.formType = legacyTypeMap[options.formType]; + } + + if(typeof options === 'function') yes = options; if(options.area){ @@ -1518,9 +1530,12 @@ layer.prompt = function(options, yes){ if (options.placeholder) { placeholder = ' placeholder="' + options.placeholder + '"'; } - var prompt, content = options.formType == 2 ? '' : function () { - return ''; - }(); + var prompt; + var content = options.formType == 'textarea' + ? '' + : function () { + return ''; + }(); var success = options.success; delete options.success;