Html在窗体中输入占位符字段中的仅颜色(*)符号 [英] Html Color only (*) symbol in input placeholder field in form
本文介绍了Html在窗体中输入占位符字段中的仅颜色(*)符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
<input id="firstName" name="fname" type="text" maxlength="50" placeholder="First Name *" required>
如何将占位符值中的(*)符号变为红色,而不用其他文本着色(是名字文本)?
How can I color the (*) symbol in the placeholder value red without coloring the other text with it (being First Name text)?
任何帮助都非常感谢!
谢谢!
Al
Thank you! Al
推荐答案
不幸的是,不可能改变输入中某些文字的颜色:可以尝试使用 contenteditable
div:
Unfortunately, it isn't possible to change the color of certain text in a input :( you can try to use a contenteditable
div:
<div class="input" contenteditable>First Name <span style="color:red;">*</span></div>
然后,您必须使用JS添加和删除占位符:
Then, you have to add and remove the placeholder with JS:
$(function(){
$('.input').focus(function(){
$(this).html('');
});
$('.input').blur(function(){
if($(this).html()=='') this.innerHTML='First Name <span style="color:red;">*</span>';
});
});
这篇关于Html在窗体中输入占位符字段中的仅颜色(*)符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文