Table of Contents
1. Commonly used form components
1.1 button
 
1.8 switch
1.9 textarea
2、实训小案例–问卷调查
Home WeChat Applet Mini Program Development Summarize and organize common form components of WeChat mini programs

Summarize and organize common form components of WeChat mini programs

May 06, 2022 pm 05:57 PM
WeChat applet

This article brings you relevant knowledge about WeChat Mini Program, which mainly introduces some common form components, including button, checkbox, input, label and other related issues. The following is Let's take a look, hope it helps everyone.

Summarize and organize common form components of WeChat mini programs

【Related learning recommendations: 小program learning tutorial

1. Commonly used form components

1.1 button

is a button component, which is one of the commonly used form components and is used for event triggering and form submission. Its attribute table is shown below.

Summarize and organize common form components of WeChat mini programsCode example:

<view>
  <view>7.button小案例</view>
  <view>(1)迷你按钮</view>
  <button>主要按钮</button>
  <button>次要按钮</button>
  <button>警告按钮</button>
  <view>(2)按钮状态</view>
  <button>普通按钮</button>
  <button>警用按钮</button>
  <button>加载按钮</button>
  <view>(3)增加按钮事件</view>
  <button>点我获取用户信息</button></view>
Copy after login

Summarize and organize common form components of WeChat mini programs1.2 checkbox

 

is a check box component, often used to select multiple data in a form. The <checkbox-group></checkbox-group> of the check box is the parent control, and several <checkbox></checkbox> child controls are nested inside it.  

The attributes are as follows:

##  Summarize and organize common form components of WeChat mini programs<checkbox></checkbox>

The attributes of the component are as follows: :

Code example: Summarize and organize common form components of WeChat mini programs

checkbox.wxml

<view>
  <view>8.checkbox小案例</view>
  <view>利用for循环批量生成</view>
  <checkbox-group>
    <label>
      <checkbox></checkbox>{{item.value}}
    </label>
  </checkbox-group>
</view>
Copy after login
checkbox.js

Page({
  data: {
    items: [
      { name: "tiger", value: "老虎" },
      { name: "elephant", value: "大象" },
      { name: "lion", value: "狮子", checked: "true" },
      { name: "penguin", value: "企鹅" },
      { name: "elk", value: "麋鹿" },
      { name: "swan", value: "天鹅" },
    ]
  },
  checkboxChange:function(e) {
    console.log("checkbox发生change事件,携带value值为:", e.detail.value)
  }})
Copy after login

1.3 inputSummarize and organize common form components of WeChat mini programs



is an input box component, often used for inputting text (such as name, age, etc.). The attribute table is as follows:

<view>
  <view>9.input小案例</view>
  <view>(1)文字输入框</view>
  <input>
  <view>(2)密码输入框</view>
  <input>
  <view>(3)禁用输入框</view>
  <input>
  <view>(4)为输入框增加事件监听</view>
  <input></view>
Copy after login

Summarize and organize common form components of WeChat mini programs

1.4 labelSummarize and organize common form components of WeChat mini programs

  

is the label component , will not render any effect, but can be used to improve the usability of form components. When the user clicks the text within the label element, this control will be triggered. That is, when the user selects the label, the event will be passed to the form control related to the label. You can use the for attribute to bind the id, or you can put the space in Inside the tag, the corresponding properties of the component are as follows.

wxmlSummarize and organize common form components of WeChat mini programs

<view>
  <view>10.lable小案例</view>
  <view>(1)利用for属性</view>
  <checkbox-group>
    <checkbox></checkbox>
    <label>老虎</label>
    <checkbox></checkbox>
    <label>大象</label>
    <checkbox></checkbox>
    <label>狮子</label>
  </checkbox-group>
  <view>(2)label包裹组件</view>
  <checkbox-group>
    <label>
      <checkbox></checkbox>老虎    </label>
    <label>
      <checkbox></checkbox>大象    </label>
    <label>
      <checkbox></checkbox>狮子    </label>
  </checkbox-group></view>
Copy after login
1.5 form

is the form control component, used to submit the form content in the component.

A variety of components can be nested inside the control component.

Component properties are as follows:

##form.wxml

<view>
  <view>11.form小案例</view>
  <view>模拟注册功能</view>
  <form>
    <text>用户名:</text>
    <input>
    <text>密码:</text>
    <input>
    <text>手机号:</text>
    <input>
    <text>验证码:</text>
    <input>
    <button>注册</button>
    <button>重置</button>
  </form></view>
Copy after login
form.js

Page({
  onSubmit(e) {
    console.log("form发生了submit事件,携带数据为:")
    console.log(e.detail.value)
  },
  onReset() {
    console.log("form发生了reset事件,表单已被重置")
  }})
Copy after login
Summarize and organize common form components of WeChat mini programs ·Enter the test data and click The register button triggers the form submit event.

##1.6 radio



is a radio button component, which often needs to be matched with Summarize and organize common form components of WeChat mini programs component is used,

tags are nested in

. # ##<radio-group></radio-group>The component properties are as follows:## :

radio.wxml

<view>
  <view>14.radio小案例</view>
  <view>利用for循环批量生成</view>
  <radio-group>
    <block>
      <radio></radio>{{item.value}}    </block>
  </radio-group></view>
Copy after login
Summarize and organize common form components of WeChat mini programsradio.js

Page({
  data: {
    radioItems: [
      { name: 'tiger', value: '老虎' },
      { name: 'elephant', value: '大象' },
      { name: 'lion', value: '狮子', checked: 'true' },
      { name: 'penguin', value: '企鹅' },
      { name: 'elk', value: '麋鹿' },
      { name: 'swan', value: '天鹅' },
    ]
  },
  radioChange:function(e) {
    console.log("radio发生change事件,携带value值为:", e.detail.value)
  }})
Copy after login

1.7 slider

Summarize and organize common form components of WeChat mini programs  

is a sliding selector, used to visually and dynamically change the value of a variable. The attribute table is as follows:

Summarize and organize common form components of WeChat mini programsslider.wxml

<view>
  <view>15.slider小案例</view>
  <view>(1)滑动条右侧显示当前进度值</view>
  <slider></slider>
  <view>(2)自定义滑动条颜色与滑块样式</view>
  <slider></slider>
  <view>(3)禁用滑动条</view>
  <slider></slider>
  <view>(4)增加滑动条监听事件</view>
  <slider></slider></view>
Copy after login

1.8 switch

  <switch></switch>为开关选择器,常用于表单上地开关功能,属性表如下所示。

Summarize and organize common form components of WeChat mini programs

switch.wxml

<view>
  <view>16.switch小案例</view>
  <view>增加switch事件监听</view>
  <switch></switch>
  <switch></switch></view>
Copy after login

Summarize and organize common form components of WeChat mini programs

1.9 textarea

  <textarea></textarea>为多行输入框,常用于多行文字的输入。

2、实训小案例–问卷调查

survey.wxml

<view>
  <form>
    <view>1.你现在大几?</view>
    <radio-group>
      <radio></radio>大一      <radio></radio>大二      <radio></radio>大三      <radio></radio>大四    </radio-group>

    <view>2.你使用手机最大的用途是什么?</view>
    <checkbox-group>
      <label><checkbox></checkbox>社交</label>
      <label>
        <checkbox></checkbox>网购</label>
      <label>
        <checkbox></checkbox>学习</label><label>
        <checkbox></checkbox>其他</label>

    </checkbox-group>
    <view>3.平时每天使用手机多少小时?</view>
    <slider></slider>

     <view>4.你之前有使用过微信小程序吗?</view>
    <radio-group>
      <radio></radio>无      <radio></radio>有    </radio-group>

    <view>5.谈谈你对微信小程序未来发展的看法</view>
    <textarea></textarea>
    <button>提交</button>
    <button>重置</button>
  </form></view>
Copy after login

survey.js

Page({
  universityChange: function (e) {
    console.log("你选择的现在大几:", e.detail.value)
  },

  mobilChange: function (e) {
    console.log("你选择使用手机的最大用途是:", e.detail.value)
  },


  timechange: function (e) {
    console.log("你选择的每天使用手机的时间是:", e.detail.value + "小时")
  },

  programChange: function (e) {
    console.log("你选择的是否使用过微信小程序:", e.detail.value)
  },
 
 
  onSubmit(e) {
    console.log("你输入的对小程序发展前途的看法是:"+e.detail.value.textarea)

  },
  onReset() {
    console.log("表单已被重置")
  }})
Copy after login

Summarize and organize common form components of WeChat mini programs

【相关学习推荐:小程序学习教程

The above is the detailed content of Summarize and organize common form components of WeChat mini programs. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Xianyu WeChat mini program officially launched Xianyu WeChat mini program officially launched Feb 10, 2024 pm 10:39 PM

Xianyu's official WeChat mini program has quietly been launched. In the mini program, you can post private messages to communicate with buyers/sellers, view personal information and orders, search for items, etc. If you are curious about what the Xianyu WeChat mini program is called, take a look now. What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3. If you want to use it, you must activate WeChat payment before you can purchase it;

WeChat applet implements image upload function WeChat applet implements image upload function Nov 21, 2023 am 09:08 AM

WeChat applet implements picture upload function With the development of mobile Internet, WeChat applet has become an indispensable part of people's lives. WeChat mini programs not only provide a wealth of application scenarios, but also support developer-defined functions, including image upload functions. This article will introduce how to implement the image upload function in the WeChat applet and provide specific code examples. 1. Preparatory work Before starting to write code, we need to download and install the WeChat developer tools and register as a WeChat developer. At the same time, you also need to understand WeChat

Implement the drop-down menu effect in WeChat applet Implement the drop-down menu effect in WeChat applet Nov 21, 2023 pm 03:03 PM

To implement the drop-down menu effect in WeChat Mini Programs, specific code examples are required. With the popularity of mobile Internet, WeChat Mini Programs have become an important part of Internet development, and more and more people have begun to pay attention to and use WeChat Mini Programs. The development of WeChat mini programs is simpler and faster than traditional APP development, but it also requires mastering certain development skills. In the development of WeChat mini programs, drop-down menus are a common UI component, achieving a better user experience. This article will introduce in detail how to implement the drop-down menu effect in the WeChat applet and provide practical

Use WeChat applet to achieve carousel switching effect Use WeChat applet to achieve carousel switching effect Nov 21, 2023 pm 05:59 PM

Use the WeChat applet to achieve the carousel switching effect. The WeChat applet is a lightweight application that is simple and efficient to develop and use. In WeChat mini programs, it is a common requirement to achieve carousel switching effects. This article will introduce how to use the WeChat applet to achieve the carousel switching effect, and give specific code examples. First, add a carousel component to the page file of the WeChat applet. For example, you can use the &lt;swiper&gt; tag to achieve the switching effect of the carousel. In this component, you can pass b

What is the name of Xianyu WeChat applet? What is the name of Xianyu WeChat applet? Feb 27, 2024 pm 01:11 PM

The official WeChat mini program of Xianyu has been quietly launched. It provides users with a convenient platform that allows you to easily publish and trade idle items. In the mini program, you can communicate with buyers or sellers via private messages, view personal information and orders, and search for the items you want. So what exactly is Xianyu called in the WeChat mini program? This tutorial guide will introduce it to you in detail. Users who want to know, please follow this article and continue reading! What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3.

Implement image filter effects in WeChat mini programs Implement image filter effects in WeChat mini programs Nov 21, 2023 pm 06:22 PM

Implementing picture filter effects in WeChat mini programs With the popularity of social media applications, people are increasingly fond of applying filter effects to photos to enhance the artistic effect and attractiveness of the photos. Picture filter effects can also be implemented in WeChat mini programs, providing users with more interesting and creative photo editing functions. This article will introduce how to implement image filter effects in WeChat mini programs and provide specific code examples. First, we need to use the canvas component in the WeChat applet to load and edit images. The canvas component can be used on the page

How to use PHP to develop the second-hand transaction function of WeChat applet? How to use PHP to develop the second-hand transaction function of WeChat applet? Oct 27, 2023 pm 05:15 PM

How to use PHP to develop the second-hand transaction function of WeChat applet? As a popular mobile application development platform, WeChat applet is used by more and more developers. In WeChat mini programs, second-hand transactions are a common functional requirement. This article will introduce how to use PHP to develop the second-hand transaction function of the WeChat applet and provide specific code examples. 1. Preparation work Before starting development, you need to ensure that the following conditions are met: the development environment of the WeChat applet has been set up, including registering the AppID of the applet and setting it in the background of the applet.

Implement image rotation effect in WeChat applet Implement image rotation effect in WeChat applet Nov 21, 2023 am 08:26 AM

To implement the picture rotation effect in WeChat Mini Program, specific code examples are required. WeChat Mini Program is a lightweight application that provides users with rich functions and a good user experience. In mini programs, developers can use various components and APIs to achieve various effects. Among them, the picture rotation effect is a common animation effect that can add interest and visual effects to the mini program. To achieve image rotation effects in WeChat mini programs, you need to use the animation API provided by the mini program. The following is a specific code example that shows how to

See all articles