小程序:多行输入框 (textarea)

代码Github地址

一. 属性说明

属性名 类型 默认值 说明
value String 输入框的内容
placeholder String 输入框为空时占位符
placeholder-style String 指定 placeholder 的样式
placeholder-class String textarea-placeholder 指定 placeholder 的样式类
disabled Boolean false 是否禁用
maxlength Number 140 最大输入长度,设置为 -1 的时候不限制最大长度
auto-focus Boolean false 自动聚焦,拉起键盘。
focus Boolean false 获取焦点
auto-height Boolean false 是否自动增高,设置auto-height时,style.height不生效
fixed Boolean false 如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true
cursor-spacing Number 0 指定光标与键盘的距离,单位 px 。取 textarea 距离底部的距离和 cursor-spacing 指定的距离的最小值作为光标与键盘的距离
cursor Number 指定focus时的光标位置
show-confirm-bar Boolean true 是否显示键盘上方带有”完成“按钮那一栏
selection-start Number -1 光标起始位置,自动聚集时有效,需与selection-end搭配使用
selection-end Number -1 光标结束位置,自动聚集时有效,需与selection-start搭配使用
adjust-position Boolean true 键盘弹起时,是否自动上推页面
bindfocus EventHandle 输入框聚焦时触发,event.detail = { value, height },height 为键盘高度,在基础库
bindblur EventHandle 输入框失去焦点时触发,event.detail = {value, cursor}
bindlinechange EventHandle 输入框行数变化时调用,event.detail = {height: 0, heightRpx: 0, lineCount: 0}
bindinput EventHandle 当键盘输入时,触发 input 事件,event.detail = {value, cursor},**bindinput 处理函数的返回值并不会反映到 textarea 上 **
bindconfirm EventHandle 点击完成时, 触发 confirm 事件,event.detail = {value: value}

二. 代码

// wxml
<textarea class="textarea" value="{{value}}" placeholder="{{placeholder}}" placeholder-class="placeholder" maxlength="{{maxlength}}" focus="{{focus}}" auto-height="{{auto-height}}" show-confirm-bar="{{show-confirm-bar}}"></textarea>

// wxss
.textarea {
  font-size: 28rpx;
  margin: 10%;
  background-color: lightgray;
  width: 80%;
  height: 100px;
}

.placeholder {
  font-size: 28rpx;
  color: gray;
}


// js 
Page({
  data: {
    "value" : "",   // 文本的内容
    "placeholder" : "请输入文本",
    "maxlength": -1,  // 最大输入长度,设置为 -1 的时候不限制最大长度
    "focus" : true,
    "auto-height" : true,  // 是否自动增高,设置auto-height时,style.height不生效
    "adjust-position": true, // 键盘弹起时,是否自动上推页面
  }
})

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,019评论 3 119
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,678评论 25 708
  • 宿友酣然入睡 而我全无睡意 夜里看完七月与安生 许久未这样静心看完一部电影了 十三的初识到二七的终结 无论这中间发...
    小姑娘大姑娘都是姑娘阅读 207评论 0 1
  • 你好,黄姚 别说我们住厌了旧村庄, 别说我们不喜欢小客堂, 在你温暖的怀抱里, 滴落了疏散人的真...
    九妹看世界阅读 196评论 0 0
  • 翻译文本:《玩具屋》九讲 作者王文兴: 以往我的慢读,尚未字字求解,后来我深信好的小说,定然字字有道理,我不应说定...
    Jeremy_Anifacc阅读 1,036评论 0 2