Show:

bui.prompt Class

Extends bui.dialog
Module: UI

Available since 1.3.6

输入对话框,可以通过实例后的value方法获取输入的值

可以使用

预览地址: demo

控件预览

Constructor

bui.prompt

(
  • option
  • [callback]
)

Defined in src/scripts/ui/bui.prompt.js:9

Available since 1.3.6

Parameters:

  • option String | Object

    输入的文本提醒

    • placeholder String

      输入框的文本

    • content String

      输入的文本提醒

    • row String

      几行, 默认1行

    • type String

      默认 text

    • value String

      初始值

    • width Number

      默认:580

    • height Number

      默认:400

    • autoClose Number

      默认:false | true

    • needRemove Number

      1.6.6 默认:false | true(关闭的时候自动移除对话框)

    • onChange Function

      改变的时候触发

    • callback Function

      点击确定的时候触发

  • [callback] Function optional

    如果第1个参数是对象, 则第2个参数应该在第1个参数的对象callback字段, 点击回调 event.target 指点击的按钮

Example:

方法1, 简单用法, 确认提醒:

      var uiPrompt = bui.prompt("请输入您的名字",function(e){
                                              var text = $(e.target).text();
                                              if( text == "取消"){
                                                  this.close();
                                              }else{
                                                  if( this.value() ){
                                                      // 获取输入的值
                                                      bui.hint("您好,"+this.value());
                                                      this.close();
                                                  }else{
                                                      bui.hint("名字不能为空");
                                                  }
                                              }
                                          })
                                    

方法2 利用onChange做表单验证:

     bui.prompt({
                                           content:"请输入手机号码",
                                           callback: function(e){ 
                                               var text = $(e.target).text(); 
                                               console.log(this.value())
                                               if(text == "确定" && checkMobile(this.value())){ 
                                                   this.close();
                                               }
                                           },
                                           onChange: function (e) {
                                               // 校验
                                               if( !checkMobile(e.target.value) ){
                                                   e.target.value = '';
                                               }
                                           }
                                       })
                                    
                                       
                                    
                                       // 校验是否是手机号码
                                       function checkMobile(str) {
                                         var re = /^1\d{10}$/
                                         if (re.test(str)) {
                                           return true;
                                         } else {
                                           return false;
                                         }
                                       }
                                    

Methods

close

(
  • [callback]
)
chainable

关闭对话框

Parameters:

  • [callback] Function optional

    回调

Example:

       uiDialog.close();
                                                

create

(
  • option
)
chainable

动态增加对话框

Parameters:

Example:

       // 1.5.0 支持公共参数, 1.4.8 参数需要在create 里面
                                                       var dialog = bui.dialog();
                                                       // 先创建再打开
                                                       var dialogobj = dialog.create({ title:"标题", content:"提醒内容"})
                                                
                                                           dialogobj.open();
                                                

destroy

()

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1541

Available since 1.4.2

[销毁控件]

Example:

       //销毁
                                                       uiDialog.destroy();
                                                

disableClose

()

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1174

Available since 1.6.5

禁止关闭

Example:

       var status = uiDialog.disableClose();
                                                

disableOpen

()

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1144

Available since 1.6.5

禁止打开

Example:

       var status = uiDialog.disableOpen();
                                                

enableClose

()

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1189

Available since 1.6.5

允许关闭

Example:

       var status = uiDialog.enableClose();
                                                

enableOpen

()

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1159

Available since 1.6.5

允许打开

Example:

       var status = uiDialog.enableOpen();
                                                

focus

()

Defined in src/scripts/ui/bui.prompt.js:170

Available since 1.4.2

聚焦

Example:

       var uiPrompt = bui.prompt("请输入您的名字",function(ui){
                                                           
                                                      })
                                                
                                                      uiPrompt.focus();
                                                

fullscreen

(
  • [bool]
  • [callback]
)

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1078

Available since 1.7.3

全屏

Parameters:

  • [bool] Boolean optional

    是否全屏

  • [callback] Function optional

    回调

Example:

       // 开启
                                                       uiDialog.fullscreen();
                                                       // 关闭
                                                       uiDialog.fullscreen(false);
                                                

hide

(
  • [callback]
)
chainable

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:544

Available since 1.7.6

无动画关闭对话框

Parameters:

  • [callback] Function optional

    回调

Example:

       uiDialog.hide();
                                                

init

(
  • [option]
)
chainable

初始化方法,用于重新初始化结构,事件只初始化一次

Parameters:

  • [option] Object optional

    参数控件本身

isFullscreen

() Boolean

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1112

Available since 1.7.5

是否全屏

Returns:

Boolean:

是否全屏

Example:

       // 状态
                                                       let status = uiDialog.isFullscreen();
                                                

isOpen

()

检测窗口是否打开

Example:

       var status = uiDialog.isOpen();
                                                

maxmize

()

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:956

Available since 1.7.3

最大化

Example:

       uiDialog.maxmize();
                                                

minimize

(
  • [option]
)

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:849

Available since 1.7.3

最小化

Parameters:

  • [option] Object optional
    • [title] Number optional

      自定义缩小后的标题,非必需

    • [needRemove] Boolean optional

      是否允许移除图标

Example:

       uiDialog.minimize();
                                                
                                                       uiDialog.minimize({
                                                           title:"自定义标题"
                                                       });
                                                

modify

(
  • option]
  • [option.width]
  • [option.height]
  • [option.title]
  • [option.conent]
)

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1590

Available since 1.8.2

修改一些不需要重新渲染的参数

Parameters:

  • option] Object
  • [option.width] String optional

    宽度

  • [option.height] String optional

    高度

  • [option.title] String optional

    头部内容

  • [option.conent] String optional

    中间滚动内容

Example:

       //获取依赖控件
                                                       var uiDialogWidget = uiDialog.widget("toggle");
                                                

open

(
  • [callback]
)
chainable

打开对话框

Parameters:

  • [callback] Function optional

    回调

Example:

       uiDialog.open();
                                                

option

(
  • [key]
  • [value]
)
chainable

获取设置参数

Parameters:

  • [key] String | object optional

    不传则获取所有参数, 类型为string,没有第2个参数则获取某个参数

  • [value] String | number | boolean | function optional

    设置参数的时候要传,设置多个参数不用传,获取参数的时候也不用传

Example:

       //获取所有参数
                                                        //获取所有参数
                                                       var option = uiDialog.option();
                                                
                                                       //获取某个参数
                                                       var id = uiDialog.option( "id" );
                                                
                                                       //修改一个参数
                                                       uiDialog.option( "fullscreen",true );
                                                
                                                       //修改多个参数
                                                       uiDialog.option( {"fullscreen":true} );
                                                

remove

() chainable

移除对话框

Example:

       uiDialog.remove();
                                                

removebar

()

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1018

Available since 1.7.3

移除最小化窗口

Example:

       uiDialog.removebar();
                                                

render

(
  • [option]
)

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1335

Available since 1.8.0

渲染模板内容

Parameters:

  • [option] Object optional
    • [id] String optional

      填充到哪个id下,默认是当前id,可以不用传

    • [content] String optional

      填充的内容,可以是html

Example:

       uiDialog.render({
                                                           content:"自定义标题"
                                                       });
                                                

resize

(
  • [option]
)

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:746

Available since 1.7.3

重新设置高度

Parameters:

  • [option] Object optional
    • [width] Number optional

      宽度

    • [height] Number optional

      高度

Example:

revert

()

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:987

Available since 1.7.3

还原大小

Example:

       uiDialog.revert();
                                                

scroll

(
  • [bool]
  • [callback]
)

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1042

Available since 1.7.3

开启滚动条

Parameters:

  • [bool] Boolean optional

    是否开启滚动条

  • [callback] Function optional

    回调

Example:

       // 开启
                                                       uiDialog.scroll();
                                                       // 关闭
                                                       uiDialog.scroll(false);
                                                

show

(
  • [callback]
)
chainable

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:526

Available since 1.7.6

无动画打开对话框

Parameters:

  • [callback] Function optional

    回调

Example:

       uiDialog.show();
                                                

toggle

(
  • [onOpen]
  • [onClose]
)
chainable

切换显示, 默认点一次打开,点2次关闭

Parameters:

  • [onOpen] Function optional

    打开的回调, 非必需

  • [onClose] Function optional

    关闭的回调, 非必需

Example:

       $("#id").click(function(){
                                                           // 1. 只做切换
                                                           uiDialog.toggle();
                                                
                                                           // 2. 切换带回调
                                                           uiDialog.toggle(function(){
                                                               // 打开的回调
                                                           },function(){
                                                               // 关闭的回调
                                                           });
                                                       })
                                                

top

(
  • [index]
)
chainable

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1510

Available since 1.6.2

置顶

Parameters:

  • [index] Number optional

    设置指定层级

Example:

       $("#id").click(function(){
                                                           // 1. 只做切换
                                                           uiDialog.top();
                                                
                                                       })
                                                

value

()

Defined in src/scripts/ui/bui.prompt.js:146

Available since 1.3.6

获取输入的值或者设置

Example:

       var uiPrompt = bui.prompt("请输入您的名字",function(ui){
                                                           // 获取输入的值
                                                           console.log(ui.value());
                                                           // 或者
                                                           console.log(uiPrompt.value());
                                                      })
                                                

widget

(
  • [name]
)

获取依赖的控件

Parameters:

  • [name] String optional

    依赖 toggle 控件

Example:

       //获取依赖控件
                                                       var uiDialogWidget = uiDialog.widget("toggle");
                                                

Events

off

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1693

Available since 1.3.0

为控件取消绑定事件

Event Payload:

  • [type] String optional

    事件类型: "open"(打开的窗口时候触发) | "close"(关闭窗口的时候触发)

  • [callback] Function optional

    绑定的事件, this 为当前点击的菜单

Example:

       uiDialog.off("open");
                                                

on

Inherited from bui.dialog: src/scripts/ui/bui.dialog.js:1672

Available since 1.3.0

为控件绑定事件

Event Payload:

  • [type] String optional

    事件类型: "open"(打开的窗口时候触发) | "openafter" "afteropen"(打开的动画结束之后触发) | "close"(关闭窗口的时候触发)

  • [callback] Function optional

    绑定的事件, this 为当前点击的菜单

Example:

       uiDialog.on("open",function () {
                                                           // 点击的菜单
                                                           console.log(this);
                                                       });