feat(layer): layer.prompt 支持原生 input 的类型 (#2873)

* feat(layer): layer.prompt 支持原生 input 的类型

* docs: 更新 MDN 链接
This commit is contained in:
morning-star
2025-10-20 12:39:04 +08:00
committed by GitHub
parent c91f8a10d2
commit 6f7085913c
2 changed files with 20 additions and 5 deletions

View File

@@ -210,7 +210,7 @@ layer.tips('显示在目标元素上方', '#id', {
| 私有属性 | 描述 | 类型 | 默认值 |
| --- | --- | --- | --- |
| formType | 输入框类型。支持以下可选值:<ul><li> `0` 文本输入框 </li><li> `1` 密令输入框 </li><li> `2` 多行文本输入框 </li></ul> | number | `0` |
| formType | 输入框类型。支持以下可选值:<ul><li> `0` 文本输入框 </li><li> `1` 密令输入框 </li><li> `2` 多行文本输入框 </li><li> <a href="https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input#input_%E7%B1%BB%E5%9E%8B" rel="nofollow" target="_blank">MDN: input 类型</a>(2.13+) </li></ul> | number/string | `0` |
| value | 输入框初始值 | string | - |
| maxlength | 可输入的最大字符长度 | number | `500` |
| placeholder | 输入框内容为空时的占位符 | string | - |

View File

@@ -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 ? '<textarea class="layui-layer-input"' + style + placeholder + '></textarea>' : function () {
return '<input type="' + (options.formType == 1 ? 'password' : 'text') + '" class="layui-layer-input"' + placeholder + '>';
}();
var prompt;
var content = options.formType == 'textarea'
? '<textarea class="layui-layer-input"' + style + placeholder + '></textarea>'
: function () {
return '<input type="' + (options.formType || 'text') + '" class="layui-layer-input"' + placeholder + '>';
}();
var success = options.success;
delete options.success;