zoukankan      html  css  js  c++  java
  • 微信小程序开发--组件(5)

    一、editor

    富文本编辑器,可以对图片、文字进行编辑。

    编辑器导出内容支持带标签的 html和纯文本的 text,编辑器内部采用 delta 格式进行存储。

    通过setContents接口设置内容时,解析插入的 html 可能会由于一些非法标签导致解析错误,建议开发者在小程序内使用时通过 delta 进行插入。

    富文本组件内部引入了一些基本的样式使得内容可以正确的展示,开发时可以进行覆盖。需要注意的是,在其它组件或环境中使用富文本组件导出的html时,需要额外引入这段样式,并维护<ql-container><ql-editor></ql-editor></ql-container>的结构。

    图片控件仅初始化时设置有效。

    测试地址:https://developers.weixin.qq.com/miniprogram/dev/component/editor.html

    二、label

    用来改进表单组件的可用性。

    使用for属性找到对应的id,或者将控件放在该标签下,当点击时,就会触发对应的控件。 for优先级高于内部控件,内部有多个控件的时候默认触发第一个控件。 目前可以绑定的控件有:buttoncheckboxradioswitch

    <view class="section section_gap">
    <view class="section__title">表单组件在label内</view>
    <checkbox-group class="group" bindchange="checkboxChange">
      <view class="label-1" wx:for="{{checkboxItems}}">
        <label>
          <checkbox hidden value="{{item.name}}" checked="{{item.checked}}"></checkbox>
          <view class="label-1__icon">
            <view class="label-1__icon-checked" style="opacity:{{item.checked ? 1: 0}}"></view>
          </view>
          <text class="label-1__text">{{item.value}}</text>
        </label>
      </view>
    </checkbox-group>
    </view>
    
    <view class="section section_gap">
    <view class="section__title">label用for标识表单组件</view>
    <radio-group class="group" bindchange="radioChange">
      <view class="label-2" wx:for="{{radioItems}}">
        <radio id="{{item.name}}" hidden value="{{item.name}}" checked="{{item.checked}}"></radio>
        <view class="label-2__icon">
          <view class="label-2__icon-checked" style="opacity:{{item.checked ? 1: 0}}"></view>
        </view>
        <label class="label-2__text" for="{{item.name}}"><text>{{item.name}}</text></label>
      </view>
    </radio-group>
    </view>
    Page({
      data: {
        checkboxItems: [
          {name: 'USA', value: '美国'},
          {name: 'CHN', value: '中国', checked: 'true'},
          {name: 'BRA', value: '巴西'},
          {name: 'JPN', value: '日本', checked: 'true'},
          {name: 'ENG', value: '英国'},
          {name: 'TUR', value: '法国'},
        ],
        radioItems: [
          {name: 'USA', value: '美国'},
          {name: 'CHN', value: '中国', checked: 'true'},
          {name: 'BRA', value: '巴西'},
          {name: 'JPN', value: '日本'},
          {name: 'ENG', value: '英国'},
          {name: 'TUR', value: '法国'},
        ],
        hidden: false
      },
      checkboxChange: function(e) {
        var checked = e.detail.value
        var changed = {}
        for (var i = 0; i < this.data.checkboxItems.length; i ++) {
          if (checked.indexOf(this.data.checkboxItems[i].name) !== -1) {
            changed['checkboxItems['+i+'].checked'] = true
          } else {
            changed['checkboxItems['+i+'].checked'] = false
          }
        }
        this.setData(changed)
      },
      radioChange: function(e) {
        var checked = e.detail.value
        var changed = {}
        for (var i = 0; i < this.data.radioItems.length; i ++) {
          if (checked.indexOf(this.data.radioItems[i].name) !== -1) {
            changed['radioItems['+i+'].checked'] = true
          } else {
            changed['radioItems['+i+'].checked'] = false
          }
        }
        this.setData(changed)
      }
    })
    .label-1, .label-2{
        margin-bottom: 15px;
    }
    .label-1__text, .label-2__text {
        display: inline-block;
        vertical-align: middle;
    }
    
    .label-1__icon {
        position: relative;
        margin-right: 10px;
        display: inline-block;
        vertical-align: middle;
         18px;
        height: 18px;
        background: #fcfff4;
    }
    
    .label-1__icon-checked {
        position: absolute;
        top: 3px;
        left: 3px;
         12px;
        height: 12px;
        background: #1aad19;
    }
    
    .label-2__icon {
        position: relative;
        display: inline-block;
        vertical-align: middle;
        margin-right: 10px;
         18px;
        height: 18px;
        background: #fcfff4;
        border-radius: 50px;
    }
    
    .label-2__icon-checked {
        position: absolute;
        left: 3px;
        top: 3px;
         12px;
        height: 12px;
        background: #1aad19;
        border-radius: 50%;
    }
    
    .label-4_text{
        text-align: center;
        margin-top: 15px;
    }
  • 相关阅读:
    Android开发之Path类使用详解,自绘各种各样的图形!
    json数值和结构
    ajax异步请求不能刷新数据的问题
    关于javaBean中boolean类型变量的set和get注入后传到前端JS中的问题
    Js中的window.parent ,window.top,window.self详解
    db2中修改表字段的长度,查看表字段长度,以及查看表字段已存放值大小
    db2数据库中查找数据库表
    分页查询SQL
    ibatis动态语句加and 和不加and
    win7计划任务执行BAT文件问题
  • 原文地址:https://www.cnblogs.com/DreamchaserHe/p/11206681.html
Copyright © 2011-2022 走看看