简体   繁体   English

在输入掩码中,如何使输入的文本具有不同的颜色?

[英]In an input mask, how I make the entered text a different color?

I have an input mask for entering phone numbers on my website but I can't figure out how to make the entered text black while the mask is opaque.我有一个用于在我的网站上输入电话号码的输入掩码,但我不知道如何在掩码不透明时使输入的文本变黑。

<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/jquery.inputmask.bundle.js"></script>

<script>
$(document).ready(function(){

    $("#Phone-2").inputmask({"mask" : "(999) 999-9999" , "placeholder": "(123) 456-7890", "clearMaskOnLostFocus": false});


});
</script>

<style>

    
  #Phone-2{
    opacity: 25%;
    
  }
    }
</style>

You can create second input (with pointer-events: none, and different color)您可以创建第二个输入(使用指针事件:无和不同的颜色)

 $(document).ready(function() { $("#Phone-2").inputmask({ "mask": "(999) 999-9999", "placeholder": "(123) 456-7890", "clearMaskOnLostFocus": false }); $("#Phone-2").wrap("<div class='Phone-Wrapper'/>"); $("#Phone-2").parent().append('<input class="Phone-Wrapper-Input">'); $('body').on('keyup keydown change', '#Phone-2', function() { $(this).parent().find('.Phone-Wrapper-Input').val( $(this).val().substr(0, $(this)[0].inputmask.caretPos.begin) ) }) });
 #Phone-2 { opacity: 25%; }.Phone-Wrapper { position: relative; }.Phone-Wrapper-Input { position: absolute; top: 0; left: 0; pointer-events: none; background: transparent; border-color: transparent; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/5.0.7/jquery.inputmask.min.js"></script> <input type="text" id="Phone-2">

暂无
暂无

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

相关问题 如何使输入框中的第三个项目具有不同的颜色? (JS、HTML、CSS) - How can I make the third item entered into an input box a different color? (JS, HTML, CSS) 如何在不使模型验证失败的情况下屏蔽在文本输入中输入的字符? - How to mask characters entered in a text input without failing model validation? 如何使html文本输入每行是不同的颜色 - How to make html text input where each line is a different color 如何制作这样的输入掩码--:--:--? - How can I make input mask like this --:--:--? 输入文本时如何更改输入字段的背景色? - How to change the background color of an input field when text is entered? 如何在vuex.js中将在输入中输入的文本保存在“存储”中? 我在哪里弄错了? - How in vuex.js to save in the “store” the text entered in the input? Where did i make a mistake? 如何将与img的链接链接到文本输入/提交框中,然后将输入的内容传递到另一个页面? - How do I make a link with img into a text input/submit box that then passes whatever was entered to another page? 输入文本时如何使框出现? - How to make box appear when text is entered into input? 如何显示对输入的文本进行确认? - how can I show confirmation of what text was entered as input? 只要有用 javascript 输入的文本,就改变输入字段的背景颜色? - Change background color of input field as long as there is text entered with javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM