Html仅在表单中的输入占位符字段中的颜色(*)符号

前端之家收集整理的这篇文章主要介绍了Html仅在表单中的输入占位符字段中的颜色(*)符号前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下代码
  1. <input id="firstName" name="fname" type="text" maxlength="50" placeholder="First Name *" required>

如何将占位符值中的(*)符号着色为红色而不用其他文本着色(作为名字文本)?

任何帮助深表感谢!

谢谢!

解决方法

不幸的是,无法更改输入中某些文本的颜色:(您可以尝试使用一个可信的div:
  1. <div class="input" contenteditable>First Name <span style="color:red;">*</span></div>

然后,您必须使用JS添加删除占位符:

  1. $(function(){
  2. $('.input').focus(function(){
  3. $(this).html('');
  4. });
  5. $('.input').blur(function(){
  6. if($(this).html()=='') this.innerHTML='First Name <span style="color:red;">*</span>';
  7. });
  8. });

JSFiddle Demo

猜你在找的HTML相关文章