新聞中心
這篇文章將為大家詳細(xì)講解有關(guān)微信開(kāi)發(fā)中如何使用textarea,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
微信小程序 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文件代碼:
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); } }); } })
關(guān)于“微信開(kāi)發(fā)中如何使用textarea”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
當(dāng)前題目:微信開(kāi)發(fā)中如何使用textarea-創(chuàng)新互聯(lián)
路徑分享:http://fisionsoft.com.cn/article/coichi.html