欢迎光临,了解微信小程序开发,就上易用通!

小程序极速实战开发《十》input输入框

发布:2018-01-25 16:34浏览: 来源:网络 作者:tianshu

组件说明:
input 输入框。
 
效果展示
属性效果图:
 
小程序极速实战开发《十》input输入框(图1)
 
wxml


  1. <view class="content">
  2. type:有效值:text 感觉没什么区别
  3. <input  placeholder="type=text" type="text" value="" />
  4. <input  placeholder="type=number" type="number" value="" />
  5. <input  placeholder="type=idcard" type="idcard" value="" />
  6. <input  placeholder="type=digit" type="digit" value="" />
  7. password:
  8. <input   type="text" password="{{false}}" placeholder="请输入密码"/>
  9. <input   type="text" password="{{true}}" placeholder="请输入密码"/>
  10. placeholder:
  11. <input  placeholder="占位符" />
  12. disable:
  13. <input  placeholder="disable={{false}}" disabled='{{false}}'/>
  14. <input  placeholder="disable={{true}}" disabled='{{true}}'/>
  15. 最大长度:
  16. <input   maxlength="10" placeholder="maxlength='10'最多长度10字符"/>
  17. <input   maxlength="5" placeholder="maxlength='5'最多长度5字符"/>
  18. <input   maxlength="-1"  placeholder="值为-1,则不限制长度"/>
  19. </view>


wxss


  1. .content{
  2.   border:1px black solid;
  3.   margin: 10px;
  4.   font-size: 10pt;
  5.   padding: 5px;
  6. }
  7. input{
  8.   border:1px red solid;
  9. margin: 5px;
  10. }


事件效果图:
 
小程序极速实战开发《十》input输入框(图2)
 
wxml
 
    1. <view class="content">
    2. bindinput="当内容改变"
    3. <input  bindinput="bindinput"/>
    4. bindfocus:当获取焦点
    5. <input  bindfocus="bindfocus"/>
    6. bindblur:当失去焦点触发
    7. <input  bindblur="bindblur"/>
    8. 内容:
    9. <view style="color:blue">
    10. {{log}}
    11. </view>
    12. </view>
js
 
    1. Page({
    2.   data:{
    3.     log:'事件触发'
    4.   },
    5.   bindblur:function(e){
    6.     var value=e.detail.value;
    7.     this.setData({
    8.       log:"bindblur失去焦点.输入框值="+value
    9.     })
    10.   },
    11.   bindinput:function(e){
    12.     var value=e.detail.value;
    13.     this.setData({
    14.       log:"bindinput内容改变.输入框值="+value
    15.     })
    16.   },
    17.   bindfocus:function(e){
    18.     var value=e.detail.value;
    19.     this.setData({
    20.       log:"bindfocus获取焦点.输入框值="+value
    21.     })
    22.   }
    23. })
wxss
 
    1. .content{
    2.   border:1px black solid;
    3.   margin: 10px;
    4.   font-size: 10pt;
    5.   padding: 5px;
    6. }
    7. input{
    8.   border:1px red solid;
    9. margin: 5px;
    10. }
组件属性:
属性
描述
类型
默认值
value
输入框的初始内容
String
 
type
有效值:text, number, idcard, digit
String
text
password
是否是密码类型
Boolean
false
placeholder
输入框为空时占位符
String
 
placeholder-style
指定 placeholder 的样式
String
 
placeholder-class
指定 placeholder 的样式类
String
input-placeholder
disabled
是否禁用
Boolean
false
maxlength
最大输入长度, 设置为-1 的时候不限制最大长度
Number
140
auto-focus
自动聚焦,拉起键盘。页面中只能有一个 input 或 textarea标签时, 设置 auto-focus 属性
Boolean
false
focus
获取焦点(当前开发工具暂不支持)
Boolean
false
bindinput
除了date/time类型外的输入框,当键盘输入时,触发input事件,处理函数可以直接 return 一个字符串,将替换输入框的内容。
EventHandle
 
bindfocus
输入框聚焦时触发event.detail = {value: value}
EventHandle
 
bindblur
输入框失去焦点时触发event.detail = {value: value}
EventHandle
 

属性解析:
wxml
 
    1. <!--属性:-->
    2. <!--value:输入框内容-->
    3. <input value="内容"/>
    4. <!--type:有效类型text,number,idcard,digit,小编感觉其他三个和text没有明显区别,不清楚是什么问题,正常number应该只允许输入数字,但结果和text一样-->
    5. <input type="text"/>
    6. <input type="number"/>
    7. <input type="idcard"/>
    8. <input type="digit"/>
    9. <!--password:密码格式 boolean需要{{}}表示-->
    10. <input password="{{true}}"/>
    11. <input password/>  等同于  <input password="{{false}}"/>
    12. <!--placeholder:占位符,对输入框内容提示-->
    13. <input placeholder="占位符" placeholder-class="占位符静态样式"   placeholder-style="占位符动态样式,可用{{}}进行动态赋值"/>
    14. <!--disabled:控制标签有效,或者失效状态,在失效状态,不能获取该值-->
    15. <input disabled="{{true}}"/>
    16. <input disabled/> 等同于 <input disabled="{{false}}"/>
    17. <!--maxlength:内容长度限制,默认140-->
    18. <input  maxlength="100"/>
    19. <input  maxlength/> 等同于 <input  maxlength="140"/>
    20. <!--focus:初始化时,获取输入焦点(目前开发工具暂不支持)-->
    21. <input  focus="{{true}}"/>
    22. <input focus/> 等同于 <input focus="{{false}}"/>
    23. <!--auto-focus:当界面只有一个input,自动获取焦点-->
    24. <input   auto-focus="{{true}}"/>
    25. <input   auto-focus/> 等同于 <input auto-focus="{{false}}"/>
    26. <!--事件:-->
    27. <!--bindinput:当内容改动时触发-->
    28. <input bindinput="自己定义函数名">
    29. <!--bindfocus:当获取焦点,可用输入状态时触发-->
    30. <input bindfocus="自己定义函数名">
    31. <!--bindblur:当失去焦点触发-->
    32. <input bindblur="自己定义函数名">





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。