在微信小程序开发中如何使在弹出的输入框中输入的值在页面中排列?且使输入框自动清空。







在微信小程序开发中如何使在弹出的输入框中输入的值在页面中排列?且使输入框自动清空。







监听事件中去处理,输入完后,清空文本框中的内容就可以了。
Page({
data: {
inputValue: '' // 输入框的初始值为空
},
onInput: function(e) {
this.setData({
inputValue: e.detail.value // 更新输入框的值
});
},
onConfirm: function() {
// 将输入框的值添加到显示容器中,并清空输入框
var value = this.data.inputValue;
if (value) {
var inputValues = this.data.inputValues || [];
inputValues.push(value);
this.setData({
inputValues: inputValues,
inputValue: ''
});
}
}
});