zoukankan      html  css  js  c++  java
  • textarea层级过高的解决办法

    方法一:微信开发者文档中使用了<cover-view>元素遮住textarea

    方法二:封装一个textarea(原理通过view标签来代替不点击输入时的状态)

    wxml

    <view class="wrap wrap-class">
      <view 
        class="placeholder placeholder-class" 
        style="{{placeholder-style}}" hidden="{{value}}"
      >{{placeholder}}</view>
      <textarea 
        wx:if="{{showTextArea}}"
        class="textarea textarea-class"
        value="{{value}}" 
        disabled="{{disabled}}"
        maxlength="{{maxlength}}" 
        auto-focus="{{autoFocus}}" 
        disable-default-padding="true"
        focus="{{focus}}" 
        fixed="{{fixed}}"
        auto-height="{{auto-height}}" 
        bindinput="handleInput" 
        bindfocus="handleFocus" 
        bindblur="handleBlur" 
        bindconfirm="{{handleConfirm}}"
        bindkeyboardheightchange="bindkeyboardheightchange"
        style="{{textarea-style}}"
        maxlength="50"
      /> 
      <view wx:else 
        class="content textarea-class" 
        bindtap="handleTap"
        style="{{virtual-textarea-style}}"
      >
        {{value}}
      </view>
    </view>
    

      css

    .wrap {
      position: relative;
      z-index: 1;
    }
    .placeholder {
      position:absolute;
      top: 0;
      left: 0;
      z-index: -1;
      color: #bebebe;
     
    }
    .textarea, .content {
      display: block;
      padding: 0;
       530rpx;
      height: 90rpx;
      overflow: hidden;
      box-sizing: border-box;
      margin: 0;
      /* background-color: red; */
    }
    .content{
      flex-wrap: wrap;
      white-space:normal;
      word-break:break-all;
      word-wrap:break-word;
       530rpx;
      height: 90rpx;
    }
    

      js

    // components/multiInput/index.js
    Component({
      /**
       * 组件的属性列表
       */
      externalClasses: ['textarea-class', 'wrap-class', 'placeholder-class'],
      properties: {
        value: String, 
        disabled: Boolean,
        maxlength: {
          type: Number,
          value: -1
        },
        "auto-focus": Boolean,
        focus: Boolean,
        "auto-height": Boolean,
        fixed: Boolean,
        "placeholder-style": String,
        "textarea-style": String,
        "virtual-textarea-style": String,
        placeholder: String,
        "cursor-spacing": {
          type: Number,
          value: 0
        },
        cursor: {
          type: Number,
          value: -1
        },
        "show-confirm-bar": {
          type: Boolean, 
          value: true
        },
        "show-confirm-bar": {
          type: Number,
          value: -1
        },
        "selection-end": {
          type: Number,
          value: -1
        },
        "adjust-position": {
          type: Boolean,
          value: true
        },
        "hold-keyboard": Boolean,
    
      },
    
      /**
       * 组件的初始数据
       */
      data: {
        showTextArea: false,
        autoFocus: false
      },
    
      /**
       * 组件的方法列表
       */
      methods: {
        handleInput(e) {
          this.setData({
            value: e.detail.value
          })
          this.triggerEvent("input", e.detail)
        },
        handleTap() {
          this.setData({
            showTextArea: true,
            autoFocus: true
          })
        },
        handleBlur(e) {
          this.setData({
            showTextArea: false
          })
          this.triggerEvent("blur", e.detail)
        },
        handleFocus(e) {
          this.triggerEvent("focus", e.detail)
        },
        bindkeyboardheightchange(e) {
          this.triggerEvent("bindkeyboardheightchange", e.detail)
        }
      }
    })
    

      json

    {
      "component": true,
      "usingComponents": {}
    }
    

      对应的页面引入就完事了

    {
        "navigationBarTitleText": "确认订单",
        "usingComponents": {
            "multiline": "/components/textarea/index"
        }
    }
    

      

  • 相关阅读:
    Linux进阶之bond链路聚合
    Linux服务之cobbler批量部署篇
    Linux进阶之排错
    shell基础之综合练习
    shell基础之99乘法表
    Linux进阶之VMware Linux虚拟机运行提示“锁定文件失败 虚拟机开启模块snapshot失败”的解决办法
    Linux服务之DNS服务篇
    linux服务之NTP及chrony时间同步
    八大排序算法汇总
    堆排序
  • 原文地址:https://www.cnblogs.com/xiaohuohuai/p/13560286.html
Copyright © 2011-2022 走看看