微信小程序 獲得用戶輸入內容


在微信小程序里,如何獲得用戶輸入的內容??

js: document.getElementById("Content").value

jq:$("#Content").val()

在微信小程序中並不能這樣寫。

可以通過組件的屬性 bindchange 將用戶輸入的儲存存起來

test.wxml

<input id="postalCode" bindchange="bindChange" type="number" placeholder="輸入郵政編碼" auto-focus />

<input id="mail" bindchange="bindChange" type="number" placeholder="請輸入郵箱地址" />

test.js

var inputContent = {}

Page({
  data: {
    inputContent: {}
  },
    bindChange: function(e) {
        inputContent[e.currentTarget.id] = e.detail.value
    }
})

后台輸出

 

如果你有更好的方法實現獲得用戶輸入內容,歡迎在評論區評論


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM