输入框
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
value | string | 输入框的初始内容 | ||
type | string | text | input 的类型 | |
password | boolean | false | 是否是密码类型 | |
placeholder | string | 输入框为空时占位符 | ||
placeholder-style | string | 指定 placeholder 的样式 | ||
placeholder-class | string | input-placeholder | 指定 placeholder 的样式类 | |
disabled | boolean | false | 是否禁用 | |
max-length | number | 140 | 最大输入长度,设置为 -1 的时候不限制最大长度 | |
maxlength | number | 140 | 最大输入长度,设置为 -1 的时候不限制最大长度(对齐微信, 小红书8.13版本开始使用) | |
focus | boolean | false | 获取焦点 | |
cursor | number | 指定focus时的光标位置 | ||
selection-start | number | -1 | 光标起始位置,自动聚集时有效,需与selection-end搭配使用 | |
selection-end | number | -1 | 光标结束位置,自动聚集时有效,需与selection-start搭配使用 | |
adjust-position | boolean | true | 键盘弹起时,是否自动上推页面 | |
confirm-type | string | next | 设置键盘右下角按钮的文字,仅在type='text'时生效 | |
confirm-hold | boolean | false | 点击键盘右下角按钮时是否保持键盘不收起 | |
cursor-spacing | number | 0 | 指定光标与键盘的距离,取 input 距离底部的距离和 cursor-spacing 指定的距离的最小值作为光标与键盘的距离 | |
gesture | boolean | false | 是否支持手势。Android 支持 | |
bindinput | eventhandle | 键盘输入时触发,event.detail = {value, cursor, keyCode},keyCode 为键值,处理函数可以直接 return 一个字符串,将替换输入框的内容 | ||
bindfocus | eventhandle | 输入框聚焦时触发,event.detail = { value, height },height 为键盘高度 | ||
bindblur | eventhandle | 输入框失去焦点时触发,event.detail = { value, encryptedValue, encryptError } | ||
bindconfirm | eventhandle | 点击完成按钮时触发,event.detail = { value } |
值 | 说明 |
---|---|
text | 文本输入键盘 |
number | 数字输入键盘 |
值 | 说明 |
---|---|
send | 右下角按钮为“发送” |
search | 右下角按钮为“搜索” |
next | 右下角按钮为“下一个” |
go | 右下角按钮为“前往” |
done | 右下角按钮为“完成” |
<view class="page-body"> <view class="page-section"> <view class="weui-cells__title">控制输入的input</view> <view class="weui-cells weui-cells_after-title"> <view class="weui-cell weui-cell_input"> <input class="weui-input" bindinput="bindReplaceInput" placeholder="连续的两个1会变成2" /> </view> </view> </view> <view class="page-section"> <view class="weui-cells__title">控制键盘的input</view> <view class="weui-cells weui-cells_after-title"> <view class="weui-cell weui-cell_input"> <input class="weui-input" bindinput="bindHideKeyboard" placeholder="输入123自动收起键盘" /> </view> </view> </view> <view class="page-section"> <view class="weui-cells__title">密码输入的input</view> <view class="weui-cells weui-cells_after-title"> <view class="weui-cell weui-cell_input"> <input class="weui-input" password type="text" placeholder="这是一个密码输入框" /> </view> </view> </view> </view>