输入文本标签,键入值后无法设置 [英] input text tag, after typing value cannot be set

查看:99
本文介绍了输入文本标签,键入值后无法设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用html正确设置的文本输入. 当调用此方法时,按下按钮:

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

推荐答案

您正在设置输入的value属性,而不是设置输入的实际值.

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

这是您想要的代码行:

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

这篇关于输入文本标签,键入值后无法设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆