微信小程序设置表单input为只读

若有对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",在微信小程序可以实现只读不可编辑但仍可把值传递出去的效果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值