其他分享
首页 > 其他分享> > 怎么通过js赋值input的value?

怎么通过js赋值input的value?

作者:互联网

直接setvalue 不行的; 保存后就消失了;

 

可以使用此方法: 

const input = document.querySelector('#wtbusername')
function setInputValue(input, value){
  if(!input.disabled){
    input.disabled = true
  }
  input.value = value
}
setInputValue(input, 'hello')

  



作者:虚鲲菜菜子
链接:https://www.zhihu.com/question/437353645/answer/1673995042
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

标签:value,js,disabled,setInputValue,作者,input,转载
来源: https://www.cnblogs.com/wingxyz/p/16699388.html