Home>Article>WeChat Applet> Summarize and organize common form components of WeChat mini programs

Summarize and organize common form components of WeChat mini programs

WBOY
WBOY forward
2022-05-06 17:57:21 4631browse

This article brings you relevant knowledge aboutWeChat 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:

 7.button小案例 (1)迷你按钮    (2)按钮状态    (3)增加按钮事件 

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. Theof the check box is the parent control, and severalchild controls are nested inside it.

The attributes are as follows:

##  Summarize and organize common form components of WeChat mini programs

The attributes of the component are as follows: :

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

checkbox.wxml

 8.checkbox小案例 利用for循环批量生成    
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) }})

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:

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

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

 10.lable小案例 (1)利用for属性         (2)label包裹组件     
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

 11.form小案例 模拟注册功能  用户名:  密码:  手机号:  验证码:    
form.js

Page({ onSubmit(e) { console.log("form发生了submit事件,携带数据为:") console.log(e.detail.value) }, onReset() { console.log("form发生了reset事件,表单已被重置") }})
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 withSummarize and organize common form components of WeChat mini programs component is used,

tags are nested in

. # ##The component properties are as follows: ## :

radio.wxml

 14.radio小案例 利用for循环批量生成   {{item.value}}  
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) }})

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

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

1.8 switch

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

Summarize and organize common form components of WeChat mini programs

switch.wxml

 16.switch小案例 增加switch事件监听  

Summarize and organize common form components of WeChat mini programs

1.9 textarea

为多行输入框,常用于多行文字的输入。

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

survey.wxml

 
1.你现在大几? 大一 大二 大三 大四 2.你使用手机最大的用途是什么? 3.平时每天使用手机多少小时? 4.你之前有使用过微信小程序吗? 5.谈谈你对微信小程序未来发展的看法

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("表单已被重置") }})

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:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete