input text tag, after typing value cannot be set

五迷三道 提交于 2019-12-13 00:57:46

问题


I have a text input correctly set in html. When this method is called pressing a button:

this._searchInput.setAttribute("value", "pippo"+Math.random());
console.log(this._searchInput.value);

It works correctly, and input text fields shows the string with random number. Alas, if I type once inside the input text field, all subsequent calls to set value are ignored. Method is called since console outputs the same value visible in text field.

Any suggestion? Is there a reson why after typing in a text field value doesn't get updated by code anymore?

I have already found a similar question but it went unaswered: Cannot set dynamically text value in input after typing


回答1:


You are setting the value attribute of the input, not setting the input's actual value.

This is the line of code you want:

this._searchInput.value= "pippo"+Math.random();


来源:https://stackoverflow.com/questions/55070696/input-text-tag-after-typing-value-cannot-be-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!