欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序 textarea 詳解及簡(jiǎn)單使用方法

 更新時(shí)間:2016年12月05日 14:27:19   作者:鮑守營(yíng)  
這篇文章主要介紹了微信小程序 textarea 詳解及簡(jiǎn)單使用方法的相關(guān)資料,這里附有實(shí)現(xiàn)實(shí)例代碼,及解決textarea沒(méi)有bindchange事件,無(wú)法在輸入時(shí)給變量賦值的方法, 需要的朋友可以參考下

微信小程序 textarea 簡(jiǎn)易解決方案

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

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

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

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(){
  // 頁(yè)面渲染完成
 },
 onShow:function(){
  // 頁(yè)面顯示
 },
 onHide:function(){
  // 頁(yè)面隱藏
 },
 onUnload:function(){
  // 頁(yè)面關(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)到首頁(yè)
       app.func.showToast('提交成功','loading',1200);
      }else{
       app.func.showToast('提交失敗','loading',1200);
      }
  });
 }
})

 缺點(diǎn):

這樣操作后,功能就有缺陷。例如,無(wú)法即時(shí)獲取用戶文本框輸入字符個(gè)數(shù),如果有更好的解決方法,希望能學(xué)習(xí)一下!

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論