1. bindinput
事件是光標(biāo)移動發(fā)生數(shù)據(jù)改變,不需要手動執(zhí)行點(diǎn)擊 。 數(shù)據(jù)自動獲取
input框內(nèi)使用屬性的方式定義事件名稱
<input bindinput='getInputValue' name='price' type='text' placeholder='輸入內(nèi)容'></input>1
在js 文件中定義事件方法獲取數(shù)據(jù)
其中
e.detail
是獲取input
數(shù)據(jù) 其中包含value
值,cursor
是獲取光標(biāo)的位置
getInputValue(e){ console.log(e.detail)// {value: "ff", cursor: 2} }
其他還有三種方法用法一致:
2. bindsubmit
攜帶 form 中的數(shù)據(jù)觸發(fā) submit 事件
bindsubmit 事件需要配合按鈕的
formType="submit"
操作設(shè)置input的name值來獲取對應(yīng)的數(shù)據(jù)
<form bindsubmit='loginForm'> <text class='login-title'>用戶登錄:</text> <input type='text' name='username' placeholder="請輸入用戶名"></input> <input type='password' name='password' placeholder="請輸入賬號密碼"></input> <view class='ligin-button'> <button formType="submit" type='primary'>點(diǎn)擊提交</button> <button formType="reset" type='primary'>重置數(shù)據(jù)表單</button> </view></form>
在js 中獲取數(shù)據(jù)
通過data.detail.value獲取數(shù)據(jù),獲得的是json對象數(shù)據(jù)鍵值對一一對應(yīng)
loginForm: function(data) { console.log(data.detail.value)// {username: "hgj", password: "fsdfsd"} var username = data.detail.value.username var password = data.detail.value.password; }