若有对Web开发或者js/jsp或者HTML有一定了解的话,大家一定对表单不陌生。而对于表单中有时想设置文本框input只读(即不可编辑)时,有readonly和disable两种方法。
HTML中,简单地说,readonly和disable两种属性都能使input只读不可编辑,差别在于表单提交时,readonly会将值传递出去,而disable不会将值传递出去。(tip:一些开发中,为了防止用户多次点击提交造成重复提交时,可设置用户点击提交后submit设置为disable)
而在小程序中,官方文档给的input属性并不多。(详见:https://developers.weixin.qq.com/miniprogram/dev/component/input.html)
在小程序进行将表单input设置为只读时,可以:
<text>pages/packet/user/modifyUser.wxml</text>
修改用户信息:
<form bindsubmit="modifyUserForm" bindreset="modifyUserReset">
用户账号: <input value="{{userList.account}}" name="account" placeholder="用户账号..." disabled="true"/>
用户密码: <input value="{{userList.password}}" name="password" placeholder="用户密码..."/>
发件地邮编: <input value="{{userList.numberFrom}}" name="numberFrom" placeholder="用户发件地邮编..."/>
发件地址: <input value="{{userList.detailFrom}}" name="detailFrom" placeholder="用户发件地址..."/>
接收地邮编: <input value="{{userList.numberTo}}" name="numberTo" placeholder="用户接收地邮编..."/>
接收地址: <input value="{{userList.detailTo}}" name="detailTo" placeholder="用户接收地址..."/>
<button form-type="submit">提交</button>
<button form-type="reset">重置</button>
</form>
可看到已设置disable的账号那一项,鼠标点击是不能编辑的:
但在后台能够成功取到账号的值:
也就是这么写disabled="true"
,在微信小程序可以实现只读不可编辑但仍可把值传递出去的效果。