繁体   English   中英

更改单个占位符字符颜色?

[英]Change a single placeholder character color?

无论如何,是否有可能使该脚本正常运行,我想在尝试使用CSS的特定占位符的末尾添加一个红色(*):after伪,在chrome中效果很好。 但是我需要跨浏览器。

我有一些用红色( )替换任何( )的 Java脚本,但是在占位符中显示了标签。

<head>
#inputFormBorder ::-webkit-input-placeholder:after {color:red;content:"*";}
#inputFormBorder ::-moz-placeholder:after {color:red;content:"*";}
#inputFormBorder :-ms-input-placeholder:after {color:red;content:"*";}

#inputFormBorder0 ::-webkit-input-placeholder:after {content:"";}
#inputFormBorder0 ::-moz-placeholder:after {content:"";}
#inputFormBorder0 :-ms-input-placeholder:after {content:"";}

input {width:300px;}
</head>
<body>
<h4>this only works in chrome</h4>
<div id="inputFormBorder">
    <input name="UserName" type="text" id="UserName" placeholder="User Name or Email">
   <div>

       <br><br>

<h4>cross browser?</h4>
<div id="inputFormBorder0">
    <input name="UserName" type="text" id="UserName" placeholder="User Name or Email*">
   <div>

  <br><br>

<div id="inputFormBorder">
    js turned this red *
   <div>

<script>
$('#inputFormBorder0').each(function () {
    $(this).html($(this).html().replace(/(\*)/g, '<span style="color: red;">*</span>'));
});
</script>
</body>

https://jsfiddle.net/zo16ruxd/15/

这个jsfiddle应该更好地解释。

谢谢!

你的意思是这样的吗? https://jsfiddle.net/zo16ruxd/17/如果是,为什么不使用<span>

暂无
暂无

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

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