簡體   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