设置 value 属性后,如何使 textarea 像用户输入一样更新?
我正在构建一个 Chrome 扩展程序,使用户能够将预设回复插入其频道上的 Youtube 评论中。我使用 textarea
的 value 属性插入文本:
getHighlightedComment().querySelector("textarea").value = cannedResponseText
问题是,textarea
不会调整其大小,并且提交按钮不会启用,直到我手动输入另一个字母。
我安装了一个不同的扩展,它具有类似的功能,但没有这些问题,所以这一定是可能的。
我已经尝试手动发送 keypress
/keydown
/keyup
事件,但它们似乎无法在 textarea
内工作>s。没有任何反应发生。
I'm building a Chrome extension that enables the user to insert canned responses into Youtube comments on their channel. I insert the text using textarea
's value property:
getHighlightedComment().querySelector("textarea").value = cannedResponseText
The problem is, the textarea
doesn't adapt its size and the submit button doesn't get enabled until I type in another letter manually.
I have a different extension installed that has a similar functionality that doesn't have these problems, so it must be possible.
I already tried sending keypress
/keydown
/keyup
events manually, but they seem to not work inside textarea
s. Nothing happens in response to them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您需要在实际更改后在您的字段上触发一些事件这里是您可以如何处理它。
UPD。
我想这更多是关于
onchange
事件。此外,您还需要检查文本区域的 CSS - 行未硬编码,高度和最大高度未硬编码(值为“auto”)。
以下是一些使用 JS 更新它的解决方法 - https://stackoverflow.com/a/25621277/9994697
I guess you need to trigger some event on your field after actual change Here is how you can deal with it.
UPD.
I guess it is more about
onchange
event.Also you need to check the CSS of your textarea - rows are not hardcoded, height and max-height is not hardcoded (has value 'auto').
Here are some workarounds to update it with JS - https://stackoverflow.com/a/25621277/9994697