微信小程序中textarea怎么用

這篇文章給大家分享的是有關(guān)微信小程序中textarea怎么用的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

玉環(huán)網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,玉環(huán)網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為玉環(huán)成百上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的玉環(huán)做網(wǎng)站的公司定做!

微信小程序 textarea 簡易解決方案

微信小程序中textarea沒有bindchange事件,所以無法在輸入時(shí)給變量賦值。

雖然可以使用bindblur事件,但是綁定bindblur事件,如果再點(diǎn)擊按鈕,則先執(zhí)行完按鈕事件后,再去執(zhí)行bindblur事件,所以在js文件取不到輸入值,

解決方法:結(jié)合from表單,textarea文本框輸入后,再去點(diǎn)擊提交按鈕,這時(shí)會(huì)先執(zhí)行textarea事件(獲取文本框輸入內(nèi)容),再去執(zhí)行數(shù)據(jù)提交,這樣問題就解決了

wxml文件代碼:

<form bindsubmit="evaSubmit">
   <textarea name="evaContent" maxlength="500" value="{{evaContent}}" class="weui-textarea" placeholder="填寫內(nèi)容(12-500字)"bindblur="charChange" />     
   <button formType="submit" disabled="{{subdisabled}}" class="weui-btn mini-btn" type="primary" size="mini">提交</button>
 </form>

js文件代碼:

var app = getApp();
Page({
 data:{
   evaContent  : ''
 },
 onLoad:function(){
 },
 onReady:function(){
  // 頁面渲染完成
 },
 onShow:function(){
  // 頁面顯示
 },
 onHide:function(){
  // 頁面隱藏
 },
 onUnload:function(){
  // 頁面關(guān)閉
 },
 //事件
 textBlur: function(e){
   if(e.detail&&e.detail.value.length>0){
    if(e.detail.value.length<12||e.detail.value.length>500){
     //app.func.showToast('內(nèi)容為12-500個(gè)字符','loading',1200);
    }else{
     this.setData({
       evaContent : e.detail.value
     });
    }
   }else{
    this.setData({
      evaContent : ''
    });
    evaData.evaContent = '';
    app.func.showToast('請(qǐng)輸入投訴內(nèi)容','loading',1200);
   }
 },
 //提交事件
 evaSubmit:function(eee){  
  var that = this;
  //提交(自定義的get方法)
  app.func.req('http://localhost:1111/ffeva/complaint?content=''+this.data.evaContent),get,function(res){
      console.log(res);
      if(res.result==='1'){
       //跳轉(zhuǎn)到首頁
       app.func.showToast('提交成功','loading',1200);
      }else{
       app.func.showToast('提交失敗','loading',1200);
      }
  });
 }
})

缺點(diǎn):

這樣操作后,功能就有缺陷,例如,無法即時(shí)獲取用戶文本框輸入字符個(gè)數(shù)。

感謝各位的閱讀!關(guān)于“微信小程序中textarea怎么用”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

本文題目:微信小程序中textarea怎么用
文章源于:http://muchs.cn/article14/gdscge.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、網(wǎng)頁設(shè)計(jì)公司、建站公司、全網(wǎng)營銷推廣、網(wǎng)站營銷網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)