简体   繁体   English

突出显示标记并将标记写入javascript中的文本框

[英]highlight and write a tag to textbox in javascript

I have a Textbox on a form. 我在表单上有一个文本框。 I Want to highlight the textbox and write a tag in the bottom of the text box in javascript. 我想突出显示文本框并在javascript文本框的底部写一个标签。 i am doing the following to get the value, 我正在做以下事情以获取价值,

var form = getAdjustedForm(obj, modelKey);
var reasonText = document.getElementById("AlertSuppression_Reason").value;

if (reasonText == "" || reasonText.length == 0 || reasonText == null) {         
    $('#AlertSuppression_Reason').text("This Trade will be updated.");
    document.getElementById('AlertSuppression_Reason').style.borderColor  = "red";      
}

With this the textbox is turning red but its not writing a tag. 这样,文本框将变为红色,但未写入标签。 I want something like: 我想要类似的东西:

在此处输入图片说明

You need to create a text container, like span , that's gonna be hidden by default. 您需要创建一个文本容器,例如span ,默认情况下将被隐藏。 Then you need to add an event listener like onkeyup to the textbox that's gonna detect its value's length, if the textbox is empty, then display the text. 然后,您需要在文本框中添加像onkeyup这样的事件侦听器,该事件侦听器将检测其值的长度,如果文本框为空,则显示文本。

Example in pure JS: 纯JS中的示例:

https://jsfiddle.net/9tbj2gw6/ https://jsfiddle.net/9tbj2gw6/

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

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