溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

微信小程序 input表單與redio及下拉列表的使用實例

發(fā)布時間:2020-09-30 10:46:31 來源:腳本之家 閱讀:235 作者:lqh 欄目:web開發(fā)

微信小程序 input表單與redio及下拉列表的使用實例

一個簡單的預(yù)約類型的表單,效果

微信小程序 input表單與redio及下拉列表的使用實例

主要代碼:

  <form bindsubmit="bindSave">
   <view class="form-box">
    <view class="row-wrap">
     <view class="label">聯(lián)系人</view>
     <view class="label-right">
      <input name="userName" class="input" type="text" placeholder="姓名" value="{{addressData.userName}}" />
     </view>
    </view>

    <view class="row-wrap">
     <view class="label">性別</view>
     <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 class="row-wrap">
     <view class="label">手機號碼</view>
     <view class="label-right">
      <input name="mobile" class="input" maxlength="11" type="number" placeholder="11位手機號碼" value="{{addressData.mobile}}" />
     </view>
    </view>

    <view class="row-wrap">
     <view class="label">預(yù)約項目</view>
     <picker bindchange="bindCasPickerChange" value="{{casIndex1}}" range="{{casArray}}">
      <view>
       <text>{{casArray[casIndex]}}</text>
      </view>
     </picker>


    </view>

   </view>

   <view class="btn-tyc">

    <button size="mini" bindtap="tapAddCart" class="submit" type="primary" formType="submit">提交預(yù)約</button>
   </view>

   <button size="mini" bindtap="tlp_phone" class="phone" type="primary">撥打電話</button>
  </form>

.js文件

 data: {
  nickName: "",
  avatarUrl: "",
  casArray: ['雙眼皮', 'TBM', '隆胸', '減肥', 'qita'],
  userName: '',
  mobile: '',
  Gender: 'female',
  casIndex: 0,
  items: [
   { name: 'male', value: '男' },
   { name: 'female', value: '女', checked: 'true' },
  ]
 },
 radioChange: function (e) {
  console.log('值:', e.detail.value)
  this.setData({
   Gender: e.detail.value
  })
 },
 /**
  * 生命周期函數(shù)--監(jiān)聽頁面加載
  */
 bindCasPickerChange: function (e) {
  console.log(this.data.casArray);
  console.log('下拉選擇的是', this.data.casArray[e.detail.value])
  this.setData({
   casIndex: e.detail.value
  })
 },

具體的表單樣式可以自己調(diào)整,wxss樣式文件代碼不寫了

參照官方文檔form組件

https://mp.weixin.qq.com/debug/wxadoc/dev/component/form.html

如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI