Home > WeChat Applet > Mini Program Development > Detailed explanation of WeChat applet component: radio single selection item

Detailed explanation of WeChat applet component: radio single selection item

高洛峰
Release: 2017-03-27 11:20:20
Original
3151 people have browsed it

radio single-select item component description:

radio: single-select item.

radio-group:

Single-item selector, internally composed of multiple .

The radio single-select item sample code runs as follows:

Detailed explanation of WeChat applet component: radio single selection item

The following is the WXML code:

<view class="page">
  <view class="page__hd">
    <text class="page__title">radio</text>
    <text class="page__desc">单选框</text>
  </view>
  <view class="page__bd">
    <view class="section section_gap">
      <radio-group class="radio-group" bindchange="radioChange">
        <label class="radio" wx:for="{{items}}">
          <radio value="{{item.name}}" checked="{{item.checked}}"/>{{item.value}}
        </label>
      </radio-group>
    </view>
  </view>
</view>
Copy after login

The following is the JS code:

Page({
  data: {
    items: [
      {name: &#39;USA&#39;, value: &#39;美国&#39;},
      {name: &#39;CHN&#39;, value: &#39;中国&#39;, checked: &#39;true&#39;},
      {name: &#39;BRA&#39;, value: &#39;巴西&#39;},
      {name: &#39;JPN&#39;, value: &#39;日本&#39;},
      {name: &#39;ENG&#39;, value: &#39;英国&#39;},
      {name: &#39;FRA&#39;, value: &#39;法国&#39;},
    ]
  },
  radioChange: function(e) {
    console.log(&#39;radio发生change事件,携带value值为:&#39;, e.detail.value)
  }
})
Copy after login

The following is the WXSS code:

page {
    min-height: 100%;
    flex: 1;
    background-color: #FBF9FE;
    font-size: 32rpx;
    font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif;
    overflow: hidden;
}
.page__hd{
    padding: 50rpx 50rpx 100rpx 50rpx;
    text-align: center;
}
.page__title{
    display: inline-block;
    padding: 20rpx 40rpx;
    font-size: 32rpx;
    color: #AAAAAA;
    border-bottom: 1px solid #CCCCCC;
}
.page__desc{
    display: none;
    margin-top: 20rpx;
    font-size: 26rpx;
    color: #BBBBBB;
}
.radio {
  display: block;
  margin-bottom: 20rpx;
}
.section{
    margin-bottom: 80rpx;
}
.section_gap{
    padding: 0 30rpx;
}
Copy after login

The main attributes of the radio single-item item:

radio-group:

Detailed explanation of WeChat applet component: radio single selection item

radio :

Detailed explanation of WeChat applet component: radio single selection item

The above is the detailed content of Detailed explanation of WeChat applet component: radio single selection item. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template