最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序單選框組應(yīng)用詳解

 更新時(shí)間:2022年07月19日 09:45:38   作者:不大好不大好  
這篇文章主要為大家詳細(xì)介紹了微信小程序單選框組應(yīng)用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序單選框組應(yīng)用的具體代碼,供大家參考,具體內(nèi)容如下

需求概述

有一個(gè)核選項(xiàng)數(shù)組,里面存放著核選項(xiàng)名稱、內(nèi)容、ID、選擇狀態(tài)。選擇狀態(tài)有未選擇、符合、不符合三種,默認(rèn)全部為未選擇。通過wx:for將數(shù)組渲染到頁面,每個(gè)核選項(xiàng)都有兩個(gè)單選按鈕,分別是符合和不符合按鈕,點(diǎn)擊對應(yīng)按鈕會(huì)將改變對應(yīng)那條元素中的選擇狀態(tài)的值,且點(diǎn)擊不符合時(shí),會(huì)顯示出一個(gè)文本域,讓用戶輸入不符合原因。

頁面最下面有一個(gè)提交按鈕,點(diǎn)擊時(shí)會(huì)遍歷核選項(xiàng)數(shù)組,若有選擇狀態(tài)為未選擇的項(xiàng),則無法提交,并提醒。

效果圖如下

直接上代碼

wxml文件

<block wx:for="{{SmallItem}}" wx:key="itemID">
? ? <view class="SmallItemView">
? ? ? ? <view class="infoView">
? ? ? ? ? ? <!-- 核選項(xiàng)的基本信息,例如名稱、內(nèi)容 -->
? ? ? ? ? ? <view class="SmallItemName">
? ? ? ? ? ? ? ? <label for="">核選項(xiàng)名稱:</label>
? ? ? ? ? ? ? ? <text>{{item.itemName}}</text>
? ? ? ? ? ? </view>
? ? ? ? ? ? <view class="SmallItemContent" >
? ? ? ? ? ? ? ? <label for="">核選項(xiàng)內(nèi)容:</label>
? ? ? ? ? ? ? ? {{item.itemContent}}
? ? ? ? ? ? </view>
? ? ? ? </view>
? ? ? ? <view class="reasonView" hidden="{{item.AccordWith=='不符合'?false:true}}">
? ? ? ? ? ? <!-- 不符合的時(shí)候顯示的文本域 -->
? ? ? ? ? ? <textarea placeholder="請輸入不符合原因"?
? ? ? ? ? ? ? ? ? ? ? maxlength="-1"?
? ? ? ? ? ? ? ? ? ? ? bindblur="inputChange"
? ? ? ? ? ? ? ? ? ? ? data-index="{{index}}">
? ? ? ? ? ? </textarea>
? ? ? ? </view>
? ? ? ? <view class="counterView">
? ? ? ? ? ? 第{{index+1}}項(xiàng)/共{{SmallItem.length}}項(xiàng)
? ? ? ? </view>
? ? ? ? <view class="radioView">
? ? ? ? ? ? <!-- 核選項(xiàng)的單選框 -->
? ? ? ? ? ? <radio-group bindchange="radioChange" data-index="{{index}}">
? ? ? ? ? ? ? ? <radio value="符合">符合</radio>  <!--前面有兩個(gè)中文全角空格-->
? ? ? ? ? ? ? ? <radio value="不符合">不符合</radio>
? ? ? ? ? ? </radio-group>
? ? ? ? </view>
? ? </view>
</block>
<button type="default" class="SubmitBtn" bind:tap="HXXSubmit">提交</button>

wxss文件

.SmallItemView {
? ? background-color: rgba(169, 169, 169, 0.329);
? ? padding: 5px;
? ? margin: 3px;
? ? border-radius: 3px;
? ? margin-bottom: 10px;
? ? /* box-shadow: 0px 2px 4px 2px #120f0f5c; */
}

.infoView {
? ? margin-bottom: 5px;
}

.SmallItemName {
? ? /* 核選項(xiàng)名稱view */
? ? background-color: white;
? ? margin-bottom: 2px;
? ? border-radius: 3px;
? ? padding: 2px;
}

.SmallItemName>label {
? ? display: block;
? ? font-weight: bold;
}

.SmallItemContent {
? ? /* 核選項(xiàng)內(nèi)容 */
? ? background-color: white;
? ? margin-bottom: 2px;
? ? border-radius: 3px;
? ? padding: 2px;
}

.SmallItemContent>label {
? ? display: block;
? ? font-weight: bold;
}

.reasonView {
?? ?/*不符合原因文本域樣式*/
? ? background-color: white;
? ? padding: 2px;
? ? border-radius: 3px;
? ? margin-bottom: 3px;
}

.radioView { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? text-align: center;
}

.counterView {
? ? text-align: center;
? ? font-size: x-small;
? ? background-color: white;
? ? margin-bottom: 5px;
}

.SubmitBtn {
? ? /* 提交按鈕樣式 */
? ? width: 90% !important;
? ? margin: 5px 10px;
}

js文件

// pages/RadioDemo/RadioDemo.js
Page({
? ? data: {
? ? ? ? SmallItem: [
? ? ? ? ? ? { itemID: "1", itemName: "核選項(xiàng)1", itemType: "核選項(xiàng)", itemContent: "核選項(xiàng)內(nèi)容1", AccordWith: "未選", textareaContent: "" },
? ? ? ? ? ? { itemID: "2", itemName: "核選項(xiàng)2", itemType: "核選項(xiàng)", itemContent: "核選項(xiàng)內(nèi)容2", AccordWith: "未選", textareaContent: "" },
? ? ? ? ? ? { itemID: "3", itemName: "核選項(xiàng)3", itemType: "核選項(xiàng)", itemContent: "核選項(xiàng)內(nèi)容3", AccordWith: "未選", textareaContent: "" },
? ? ? ? ? ? { itemID: "4", itemName: "核選項(xiàng)4", itemType: "核選項(xiàng)", itemContent: "核選項(xiàng)內(nèi)容4", AccordWith: "未選", textareaContent: "" },
? ? ? ? ? ? { itemID: "5", itemName: "核選項(xiàng)5", itemType: "核選項(xiàng)", itemContent: "核選項(xiàng)內(nèi)容5", AccordWith: "未選", textareaContent: "" },
? ? ? ? ? ? { itemID: "6", itemName: "核選項(xiàng)6", itemType: "核選項(xiàng)", itemContent: "核選項(xiàng)內(nèi)容6", AccordWith: "未選", textareaContent: "" }
? ? ? ? ]
? ? },
? ? radioChange: function(e) {
? ? ? ? // console.log("radio的值為:" + e.detail.value); //獲取radio的值
? ? ? ? // console.log("元素下標(biāo)為:" + e.currentTarget.dataset.index); //獲取元素在數(shù)組中的下標(biāo)
? ? ? ? let ValRadio = e.detail.value;
? ? ? ? let EleIndex = e.currentTarget.dataset.index;
? ? ? ? let key = 'SmallItem[' + EleIndex + '].AccordWith';
? ? ? ? //更改數(shù)組SmallItem[EleIndex]中AccordWith的值
? ? ? ? this.setData({
? ? ? ? ? ? [key]: ValRadio
? ? ? ? });
? ? ? ? // console.log("SmallItem數(shù)組改變后", this.data.SmallItem);
? ? },
? ? HXXSubmit: function(e) {
? ? ? ? //點(diǎn)擊提交按鈕,會(huì)獲取data中的數(shù)組SmallItem,并且遍歷其中的AccordWith屬性的值
? ? ? ? //若有AccordWith的值為“未選”,則彈出提示框,且事件執(zhí)行結(jié)束
? ? ? ? //否則將數(shù)組傳回后臺(tái),進(jìn)行保存

? ? ? ? let arSmallItem = this.data.SmallItem; //獲取data中的數(shù)組SmallItem
? ? ? ? for (let i = 0; i < arSmallItem.length; i++) {
? ? ? ? ? ? //遍歷數(shù)組
? ? ? ? ? ? if (arSmallItem[i].AccordWith == "未選") {
? ? ? ? ? ? ? ? // console.log(arSmallItem[i].itemName + "未進(jìn)行選擇,請選擇后提交");
? ? ? ? ? ? ? ? wx.showToast({
? ? ? ? ? ? ? ? ? ? title: '第' + (i + 1) + '項(xiàng)未進(jìn)行核選\n請核選后提交',
? ? ? ? ? ? ? ? ? ? icon: 'none',
? ? ? ? ? ? ? ? ? ? duration: 2000
? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? console.log("所有核選項(xiàng)已選擇");
? ? ? ? //程序能執(zhí)行到這里,說明所有核選項(xiàng)都已經(jīng)進(jìn)行了選擇,可以進(jìn)行數(shù)據(jù)保存操作
? ? ? ? // var reqTask = wx.request({
? ? ? ? // ? ? url: '',
? ? ? ? // ? ? data: {},
? ? ? ? // ? ? header: { 'content-type': 'application/json' },
? ? ? ? // ? ? method: 'GET',
? ? ? ? // ? ? dataType: 'json',
? ? ? ? // ? ? responseType: 'text',
? ? ? ? // ? ? success: (result) => {

? ? ? ? // ? ? },
? ? ? ? // ? ? fail: () => {},
? ? ? ? // ? ? complete: () => {}
? ? ? ? // });
? ? },
? ? inputChange: function(e) {
? ? ? ? // console.log(e);
? ? ? ? let index = e.currentTarget.dataset.index; //獲取元素在數(shù)組中的下標(biāo)
? ? ? ? let content = e.detail.value; //獲取在文本域中輸入的值
? ? ? ? let key = 'SmallItem[' + index + '].textareaContent';
? ? ? ? this.setData({
? ? ? ? ? ? [key]: content
? ? ? ? });
? ? ? ? console.log("SmallItem數(shù)組改變后", this.data.SmallItem);
? ? }
})

當(dāng)存在核選項(xiàng)未進(jìn)行選擇時(shí),點(diǎn)擊保存,彈窗提醒效果圖

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

宁明县| 申扎县| 舞钢市| 津南区| 清苑县| 咸宁市| 巴马| 滦南县| 图片| 井陉县| 航空| 工布江达县| 延津县| 莆田市| 漠河县| 锡林郭勒盟| 徐水县| 晋宁县| 枣庄市| 明水县| 平安县| 宣汉县| 怀远县| 井陉县| 蒙山县| 华安县| 马公市| 菏泽市| 拜泉县| 兴文县| 林西县| 望城县| 石林| 吉首市| 秦安县| 云梦县| 台湾省| 利津县| 思茅市| 泽州县| 兴化市|