<view><!-- placeholder:设置占位符 --><input placeholder="请输入内容" bindinput="bind" /><button type="primary" bindtap="onclick">发送</button><text>{{name}}</text></view>
Page({
/**
* 页面的初始数据
*/
data: {
name:''
},
//这里的e表示接收值,e可以改为任何一个值
bind(e){
console.log(e);
this.setData({
name:e.detail.value
})
},
onclick(){
console.log(this.data.name);
}
})
注意下input中获取值的方式:
默认是打印下图信息,其中输入的值在detail中,value是输入的内容,cursor是光标所在的值
