input


输入框

示例

  1. <template>
  2. <view class="page-demo">
  3. <scroller
  4. height = "{{-1}}"
  5. >
  6. <text class="title-text" >focus聚焦 web端不支持</text>
  7. <view class="input-wrap">
  8. <input placeholder="focus聚焦 web端不支持" focus="{{isfocus}}" c-bind:blur="bindblurevent"></input>
  9. </view>
  10. <text class="title-text"><text>数据绑定,value:{{inputValue}}</text></text>
  11. <view class="input-wrap">
  12. <input placeholder="数据绑定" value="{{inputValue}}" c-bind:input="inputEvent"></input>
  13. </view>
  14. <text class="title-text"><text>监听input事件,当前事件:{{eventName}}</text></text>
  15. <view class="input-wrap">
  16. <input placeholder="监听input事件" c-bind:input="testEvent" c-bind:blur="testEvent" c-bind:focus="testEvent" c-bind:confirm="testEvent"></input>
  17. </view>
  18. <text class="title-text">最大长度是5</text>
  19. <view class="input-wrap">
  20. <input placeholder="最大长度是5" maxlength="{{5}}"></input>
  21. </view>
  22. <text class="title-text">text类型的input</text>
  23. <view class="input-wrap">
  24. <input placeholder="text类型的input" type="text"></input>
  25. </view>
  26. <text class="title-text">number类型的input</text>
  27. <view class="input-wrap">
  28. <input placeholder="number类型的input" type="number"></input>
  29. </view>
  30. <text class="title-text">password类型的input</text>
  31. <view class="input-wrap">
  32. <input placeholder="password类型的input" type="password"></input>
  33. </view>
  34. <text class="title-text">禁用input</text>
  35. <view class="input-wrap">
  36. <input placeholder="禁用input" disabled="{{true}}"></input>
  37. </view>
  38. <text class="title-text">键盘右下键按钮done web端不支持</text>
  39. <view class="input-wrap">
  40. <input placeholder="键盘右下键按钮done web端不支持" return-key-type="done"></input>
  41. </view>
  42. <text class="title-text">键盘右下键按钮search web端不支持</text>
  43. <view class="input-wrap">
  44. <input placeholder="键盘右下键按钮search web端不支持" return-key-type="search"></input>
  45. </view>
  46. <text class="title-text">键盘右下键按钮next web端不支持</text>
  47. <view class="input-wrap">
  48. <input placeholder="键盘右下键按钮next web端不支持" return-key-type="next"></input>
  49. </view>
  50. <text class="title-text">键盘右下键按钮go web端不支持</text>
  51. <view class="input-wrap">
  52. <input placeholder="键盘右下键按钮go web端不支持" return-key-type="go"></input>
  53. </view>
  54. <text class="title-text">placeholderColor web端不支持</text>
  55. <view class="input-wrap">
  56. <input placeholder="placeholderColor web端不支持" placer-holder-color="#ff0000;"></input>
  57. </view>
  58. <text class="title-text">自定义样式</text>
  59. <view class="end-item">
  60. <input placeholder="自定义样式" cstyle="color: #00ff00; border: 1px solid #00f;" ></input>
  61. </view>
  62. </scroller>
  63. </view>
  64. </template>
  65. <script>
  66. class Input {
  67. data = {
  68. isfocus: false,
  69. inputValue: '',
  70. eventName: '触发的事件名称',
  71. winHeight: 0
  72. }
  73. computed = {}
  74. watch = {}
  75. methods = {
  76. inputEvent(e) {
  77. this.inputValue = e.detail.value;
  78. },
  79. testEvent(e) {
  80. this.eventName = e.type
  81. },
  82. bindblurevent() {
  83. console.log('blur')
  84. this.isfocus = false;
  85. }
  86. }
  87. mounted(res) {
  88. console.log('mounted')
  89. setTimeout(() => {
  90. this.isfocus = true;
  91. }, 300);
  92. }
  93. };
  94. export default new Input();
  95. </script>
  96. <style scoped>
  97. .page-demo {
  98. background: #FAFAFA;
  99. position: absolute;
  100. top:0;
  101. bottom:0;
  102. left:0;
  103. right:0;
  104. }
  105. .title-text {
  106. color: #999;
  107. margin: 30cpx 20cpx 10cpx;
  108. display: block;
  109. font-size: 28cpx;
  110. }
  111. .end-item {
  112. margin-bottom: 40cpx;
  113. position: relative;
  114. border-top: 1px solid #D9D9D9;
  115. border-bottom: 1px solid #D9D9D9;
  116. }
  117. .input-wrap {
  118. position: relative;
  119. border-top: 1px solid #D9D9D9;
  120. border-bottom: 1px solid #D9D9D9;
  121. }
  122. </style>
  123. <script cml-type="json">
  124. {
  125. "base": {}
  126. }
  127. </script>