[removed] How to change color to only part of the string in an input field?

后端 未结 4 703
一个人的身影
一个人的身影 2020-12-22 03:55

I have an input field where I would like to have the characters turn red after the 10th symbol.

So far I have:

var street_1 = document.getElementById         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-22 03:57

    in html you can't define sub elements in the value of input fields because it is allways a simple string and not a html element. so you only can define the color for the input element and the complete text.

    is not possible

    is the only way to mark the text

    what can be a sollution, define a simple div tag, write the value of your input filed inside that, and mark the text in that div tag by surrounding with a span tag and setting a class to this

    Edit:

    best practice is, simply show a red border on the input field and tell the user with a popup what exactly is wrong with his input (bootstrap modals or jquery-confirm.js for excample)

提交回复
热议问题