国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 熱點(diǎn) > 微信 > 正文

微信小程序bindinput與bindsubmit的區(qū)別實(shí)例分析

2024-07-22 01:18:47
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例講述了微信小程序bindinput與bindsubmit的區(qū)別。分享給大家供大家參考,具體如下:

實(shí)際上的話,bindinput還有bindsubmit是沒(méi)有任何的可比性的,但是兩者還是常常被人一起比較,為啥?

比如一個(gè)簡(jiǎn)單的搜索框,你是愿意選擇使用bindinput還是使用bindsubmit?,雖然一個(gè)是表單,一個(gè)是文本輸入框,但是兩者都有一個(gè)共同點(diǎn),就是可以去獲取到用戶的輸入信息。這個(gè)時(shí)候,問(wèn)題來(lái)了,區(qū)別在哪兒?

最簡(jiǎn)單的一段代碼在下面:

<form bindsubmit='input1input'> <input name="input1" placeholder='這個(gè)是輸入框' style='border:1rpx solid #000;'></input> <button form-type="submit">提交按鈕</button></form><input bindinput='input2input' placeholder='這個(gè)是輸入框' style='margin-top:200rpx;border:1rpx solid #000;'></input><button>提交按鈕</button>
// pages/input/input.jsPage({ data: { input1: "", input2: "" }, input1input: function (e) {  console.log(e);  console.log(e.detail.value.input1) }, input2input: function (e) {  console.log(e);  console.log(e.detail.value); }})

甚是簡(jiǎn)單,那么問(wèn)題來(lái)了,區(qū)別在哪兒?

當(dāng)然,暫時(shí)的區(qū)別只有一個(gè),就是console.log比較多,哈哈,開(kāi)玩笑的。根據(jù)深圳那邊客戶的反應(yīng),說(shuō)是使用input的時(shí)候,移動(dòng)光標(biāo)到一個(gè)地方后,輸入一個(gè)文字,會(huì)重新移動(dòng)光標(biāo)的尾部,當(dāng)然,不是上面的那些代碼了,上面的代碼是沒(méi)問(wèn)題的

有問(wèn)題的是下面的代碼:

// pages/input/input.jsPage({ data: { input1: "this is the value for input1", input2: "this is the value for input2" }, input1input: function (e) {  console.log(e);  console.log(e.detail.value.input1);  this.setData({ input1: e.detail.value.input1 }) }, input2input: function (e) {  console.log(e);  console.log(e.detail.value);  this.setData({ input2: e.detail.value }) }})
<form bindsubmit='input1input'> <input value='{{input1}}' name="input1" placeholder='這個(gè)是輸入框' style='border:1rpx solid #000;height:100rpx;'></input> <button form-type="submit">提交按鈕</button></form><input value="{{input2}}" bindinput='input2input' placeholder='這個(gè)是輸入框' style='height:100rpx;margin-top:200rpx;border:1rpx solid #000;'></input><button>提交按鈕</button>

其實(shí)原因很簡(jiǎn)單,就在一個(gè)地方,就是刷新界面的this.setData這而,為啥?因?yàn)槟闼⑿潞螅瑅alue值修改,然后呢?

然后頁(yè)面就刷新了,再然后呢?再然后就是因?yàn)槟阍O(shè)置的是光標(biāo)自動(dòng)移動(dòng)到最后一步,所以,最好的話是使用input的時(shí)候要小心點(diǎn)咯,當(dāng)然我不是說(shuō)使用input沒(méi)有使用submit好,只是適應(yīng)場(chǎng)景不同而已,比如沒(méi)必要使用bindinput的時(shí)候去刷新界面,或則說(shuō)我個(gè)人比較偏愛(ài)使用bindsbmit吧,。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 嘉义市| 焦作市| 四子王旗| 兰州市| 广德县| 安溪县| 霸州市| 阿巴嘎旗| 淳安县| 通许县| 法库县| 重庆市| 布尔津县| 湾仔区| 阳山县| 绥江县| 罗平县| 屏山县| 澄城县| 河南省| 英山县| 四子王旗| 冷水江市| 如皋市| 永州市| 汉阴县| 伊吾县| 广德县| 杨浦区| 米易县| 巴楚县| 深州市| 晋州市| 丹江口市| 开原市| 威信县| 延川县| 莫力| 铁力市| 天峨县| 华宁县|