简体   繁体   English

使用css3或javascript或jquery更改键入值的文本颜色,而不更改已经存在的值的颜色

[英]change in text color of typed value ,without changing color of already present value .using css3 or javascript or jquery

I have a date text box and in that I have use placeholder which displays dd/mm/yyyy 我有一个日期文本框,并且在其中使用了显示dd / mm / yyyy的占位符

on click of textbox it display a value="dd/mm/yyyy" ,and for that I have used mask input plugin my query is I want to change the color of the number which I'm typing, keeping remaining content color unchanged. 在单击文本框时,它会显示一个值=“ dd / mm / yyyy”,为此,我使用了掩码输入插件,我的查询是我想更改输入的数字的颜色,同时保持其余内容的颜色不变。 how can we do this. 我们应该怎么做。

Please, see this screenshot for reference. 请参阅此屏幕截图以供参考。

请参阅此屏幕截图以供参考

I tried on keypress to change color but changes everything present in the input. 我尝试在按键上更改颜色,但更改了输入中存在的所有内容。

Something cool? 很棒的东西吗? check this jsfiddle this will change color depends on value on whatever you want 检查这个jsfiddle将改变颜色取决于您想要的值

 $('.getvalueofinput').keydown(function() { var value1, value2; value1 = $('.getvalueofinput').val(); value2 = $('.equalvalue').text(); if (value1 == value2) { alert('equal'); $('.getvalueofinput').css('background-color', 'brown').css('color','white'); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type=text class="getvalueofinput"> <span class='equalvalue' value='write me'>write me</span> 

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

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