简体   繁体   English

如何在 html 的输入字段中突出显示新文本

[英]How do I highlight new text within a input field in html

Within Servicenow portals I am trying to create a input text field that has a few requirements when the user tries to make changes to the text.在 Servicenow 门户中,我尝试创建一个输入文本字段,当用户尝试对文本进行更改时,该字段有一些要求。 Within the form if the user wants to change the text that has already been added the new input text will have to be highlighted.在表单中,如果用户想要更改已添加的文本,则必须突出显示新的输入文本。 Only the new changes can be highlighted.只能突出显示新的更改。 The previous text will stay the same without any highlights.前面的文本将保持不变,没有任何突出显示。 I have looked into the html tag but that highlights the entire text field and also tried using a 'focus' within the css tag name.我查看了 html 标签,但它突出显示了整个文本字段,并且还尝试在 css 标签名称中使用“焦点”。

HTML: HTML:

<input type="text" value={{data.text2}}>

CSS: input:focus::first-line { background-color: #fff2ac; CSS: input:focus::first-line { background-color: #fff2ac; } }

You could use Javascript to position a dynamically generated span with the highlighting, on top of the input... and then update that span's text whenever the underlying input changes.您可以使用 Javascript 到 position 动态生成的跨度,并在输入顶部突出显示...然后在基础输入更改时更新该跨度的文本。

See the last option in the top answer here for more details: How to highlight text inside an input field?有关详细信息,请参阅此处最佳答案中的最后一个选项: 如何突出显示输入字段中的文本? . .

It even mentions a jQuery plug-in with this effect that you could use, or examine the source of: https://github.com/garysieling/jquery-highlighttextarea .它甚至提到了具有此效果的 jQuery 插件,您可以使用该插件,或查看以下来源: https://github.com/garysieling/jquery-highlighttextarea

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM