Here is a way to prepend a text to an input and make it unremovable.
(这是将文本添加到输入的前面并使其不可移动的一种方法。)
const input = document.getElementById('my-input')
const prependedText = "This is a prepended text"
const prependedTextLength = prependedText.length
textarea.value = prependedText
textarea.onkeyup = (ev) => {
if (textarea.value.length < prependedTextLength) {
textarea.value = prependedText
}
}
The script prepends the text to the input and watches for changes to that input.
(该脚本将文本添加到输入中,并监视对该输入的更改。)
If it detects that the length of the text is smaller than the prepended one, it will reset to that text.(如果它检测到文本的长度小于前置文本的长度,它将重置为该文本。)
Hope this helps.
(希望这可以帮助。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…