微信小程序 怎样获取input并修改呢?

我想要获取id为formDate的input 修改它的placeholder值以及它的样式,该怎样做呢?
我尝试这样获取input,但是res返回的一直是null,并且有报错

  var query = wx.createSelectorQuery();
        query.select('#formDate').fields({
          dataset:true
        },function(res){
          res.dataset
          console.log(res)
        }).exec(function(res){
          console.log(res)
        })

img

我打印的query

img

我看了你的代码,你的代码写的没有问题。如果一直提示 Cannot read property 'dataset' of null,那么有两种可能
第一:你的input的id命名的和js中的不是一个。
第二:id是同一个,但是你这个input输入框有通过wx:if来控制隐藏/显示的行为。

你直接 placeholder='{{phValue}}' phValue 在data里定义

写法有问题,参考官方文档 https://developers.weixin.qq.com/miniprogram/dev/api/wxml/NodesRef.fields.html

能看一下原始的代码截图吗?而且图里第五行这样写是不是有问题?