Html 更改输入框中文本和光标的颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8160363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing the color of the text and cursor in input box
提问by John
When a user clicks in the box below, the cursor and typed text are black. How could I make them the color of #DE2A00
?
当用户单击下面的框时,光标和键入的文本是黑色的。我怎么能让它们变成 的颜色#DE2A00
?
<div class="usernameformfield"><input tabindex="1" accesskey="u" name="username" type="text" maxlength="35" id="username" /></div>
采纳答案by newshorts
<style>
#username {
color: #DE2A00;
}
</style>
Or you could have the color change when a user clicks on the field like so:
或者,当用户单击该字段时,您可以更改颜色,如下所示:
<script type=text/javascript src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'></script>
<script type=text/javascript>
$(document).ready(function() {
$('#username').click(function(){
$(this).css({'color': '#DE2A00'});
});
});
</script>
It depends on what you want, I would check out this reference to start playing around with some things:
这取决于您想要什么,我会查看此参考资料以开始处理一些事情:
and
和
回答by Dean Marshall
Just use CSS:
只需使用CSS:
#username{color:#000;} /* black when not with focus */
#username:focus{color:#de2a00;} /* green when input has focus - only affects this specific input */
回答by John Riselvato
A little shorter one:
短一点的:
input:focus { color: #DE2A00 }
回答by Adithya Surampudi
I am assuming you need the text inside the text box in that color, if so do this
我假设您需要该颜色的文本框中的文本,如果需要,请执行此操作
<input...type="text"...style="color: #DE2A00;"/></div>
回答by Lenar Hoyt
You could these little JavaScripts:
你可以使用这些小的 JavaScript:
onfocus="this.style.background = '#DE2A00'" onblur="this.style.background = 'white'"