带有样式的旅游调查表单微信小程序带有信息保存本地功能代码

时间: 2023-08-23 15:05:54 浏览: 38
以下是一个简单的带有样式的旅游调查表单微信小程序,并且包含了信息保存本地的功能代码: 1. 首先,在wxml文件中添加以下代码: ``` <!-- 调查表单 --> <view class="form"> <view class="form-item"> <view class="form-label">姓名:</view> <input class="form-input" placeholder="请输入姓名" bindinput="bindNameInput"/> </view> <view class="form-item"> <view class="form-label">性别:</view> <radio-group class="form-radio-group" bindchange="bindGenderChange"> <label class="form-radio-label"> <radio class="form-radio" value="male" checked="{{gender==='male'}}"/> <view class="form-radio-text">男</view> </label> <label class="form-radio-label"> <radio class="form-radio" value="female" checked="{{gender==='female'}}"/> <view class="form-radio-text">女</view> </label> </radio-group> </view> <view class="form-item"> <view class="form-label">年龄:</view> <input class="form-input" type="number" placeholder="请输入年龄" bindinput="bindAgeInput"/> </view> <view class="form-item"> <view class="form-label">旅游目的地:</view> <checkbox-group class="form-checkbox-group" bindchange="bindDestinationChange"> <label class="form-checkbox-label"> <checkbox class="form-checkbox" value="beijing" checked="{{destination.indexOf('beijing')!==-1}}"/> <view class="form-checkbox-text">北京</view> </label> <label class="form-checkbox-label"> <checkbox class="form-checkbox" value="shanghai" checked="{{destination.indexOf('shanghai')!==-1}}"/> <view class="form-checkbox-text">上海</view> </label> <label class="form-checkbox-label"> <checkbox class="form-checkbox" value="guilin" checked="{{destination.indexOf('guilin')!==-1}}"/> <view class="form-checkbox-text">桂林</view> </label> </checkbox-group> </view> <button class="form-btn" bindtap="saveData">保存</button> </view> ``` 2. 在wxss文件中添加以下样式: ``` .form { display: flex; flex-direction: column; padding: 20rpx; } .form-item { display: flex; flex-direction: row; align-items: center; margin-bottom: 20rpx; } .form-label { font-size: 28rpx; color: #333; margin-right: 20rpx; } .form-input, .form-radio-group, .form-checkbox-group { flex: 1; height: 60rpx; border: 1rpx solid #ccc; border-radius: 10rpx; padding: 0 20rpx; } .form-radio-label, .form-checkbox-label { display: flex; flex-direction: row; align-items: center; margin-right: 20rpx; } .form-radio { margin-right: 10rpx; } .form-checkbox { margin-right: 10rpx; } .form-radio-text, .form-checkbox-text { font-size: 28rpx; color: #333; } .form-btn { width: 100%; height: 80rpx; background-color: #3f88ff; color: #fff; font-size: 32rpx; border-radius: 10rpx; margin-top: 40rpx; } ``` 3. 在js文件中添加以下代码: ``` Page({ data: { name: '', gender: 'male', age: '', destination: [], }, // 姓名输入 bindNameInput: function(e) { this.setData({ name: e.detail.value, }); }, // 性别选择 bindGenderChange: function(e) { this.setData({ gender: e.detail.value, }); }, // 年龄输入 bindAgeInput: function(e) { this.setData({ age: e.detail.value, }); }, // 目的地选择 bindDestinationChange: function(e) { this.setData({ destination: e.detail.value, }); }, // 保存数据 saveData: function() { wx.setStorageSync('formData', this.data); wx.showToast({ title: '保存成功', }); }, }); ``` 以上代码实现了一个简单的带有样式的旅游调查表单微信小程序,并且包含了信息保存本地的功能代码。在保存数据的函数中,我们使用了wx.setStorageSync方法将表单的数据存储在本地缓存中,并且使用了wx.showToast方法在保存成功后弹出一个提示框。

相关推荐

最新推荐

recommend-type

微信小程序实现表单校验功能

微信小程序最难实现的公共业务是什么?应该是表单校验,这篇文章主要介绍了微信小程序如何实现表单校验功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

微信小程序简单实现form表单获取输入数据功能示例

本文实例讲述了微信小程序简单实现form表单获取输入数据功能。分享给大家供大家参考,具体如下: 1、效果展示 2、关键代码 index.wxml &lt;form bindsubmit="formBindsubmit" bindreset="formReset"&gt; 用户名...
recommend-type

微信小程序表单验证功能完整实例

主要介绍了微信小程序表单验证功能,结合完整实例形式分析了微信小程序完成表单验证功能所涉及的视图与逻辑操作技巧,需要的朋友可以参考下
recommend-type

微信小程序 表单Form实例详解(附源码)

主要介绍了微信小程序 表单Form实例详解的相关资料,这里对form 表单进行了详细介绍,并附实例代码,需要的朋友可以参考下
recommend-type

微信小程序实现图片上传功能实例(前端+PHP后端)

主要给大家介绍了关于微信小程序实现图片上传功能的相关内容,文中详细介绍了前端+PHP后端的示例代码,对大家的理解和学习具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

用Spring boot和vue写一个登录注册界面

好的,这是一个比较常见的技术问题,我可以为您提供一些参考资料和思路。首先,您可以使用Spring Boot作为后端框架来处理用户认证和注册的逻辑,比如使用Spring Security实现用户登录认证。同时,您还需要设计相应的数据模型和数据库表结构来存储用户信息。在前端方面,您可以使用Vue.js作为框架来构建登录注册页面,使用Axios来发起API请求并和后端进行交互。当然,在实现过程中,还需要考虑一些具体细节,比如数据校验、安全性和用户体验等方面。希望这些信息能够帮助到您。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。