mirror of
https://github.com/layui/layui.git
synced 2026-02-09 02:09:18 +08:00
feat(layer): layer.prompt 支持原生 input 的类型 (#2873)
* feat(layer): layer.prompt 支持原生 input 的类型 * docs: 更新 MDN 链接
This commit is contained in:
@@ -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 | - |
|
| value | 输入框初始值 | string | - |
|
||||||
| maxlength | 可输入的最大字符长度 | number | `500` |
|
| maxlength | 可输入的最大字符长度 | number | `500` |
|
||||||
| placeholder | 输入框内容为空时的占位符 | string | - |
|
| placeholder | 输入框内容为空时的占位符 | string | - |
|
||||||
|
|||||||
@@ -1505,9 +1505,21 @@ var skin = function(type){
|
|||||||
|
|
||||||
// 仿系统 prompt
|
// 仿系统 prompt
|
||||||
layer.prompt = function(options, yes){
|
layer.prompt = function(options, yes){
|
||||||
var style = '', placeholder = '';
|
var style = '';
|
||||||
|
var placeholder = '';
|
||||||
options = options || {};
|
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(typeof options === 'function') yes = options;
|
||||||
|
|
||||||
if(options.area){
|
if(options.area){
|
||||||
@@ -1518,9 +1530,12 @@ layer.prompt = function(options, yes){
|
|||||||
if (options.placeholder) {
|
if (options.placeholder) {
|
||||||
placeholder = ' placeholder="' + options.placeholder + '"';
|
placeholder = ' placeholder="' + options.placeholder + '"';
|
||||||
}
|
}
|
||||||
var prompt, content = options.formType == 2 ? '<textarea class="layui-layer-input"' + style + placeholder + '></textarea>' : function () {
|
var prompt;
|
||||||
return '<input type="' + (options.formType == 1 ? 'password' : 'text') + '" class="layui-layer-input"' + placeholder + '>';
|
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;
|
var success = options.success;
|
||||||
delete options.success;
|
delete options.success;
|
||||||
|
|||||||
Reference in New Issue
Block a user