如何更改jquery中输入值的字体颜色?
继承我的代码
<h3 id="quoteDiv"></h3>
<input id="input1" type="text" onfocus="if(this.value == 'Valfri spelare') { this.value = ''; }" value="Valfri spelare"/>
var quotes = ["(tjej1) exampletext!",];
var user1 = document.getElementById("input1").value;
//Sub in the usernames
var ind = Math.floor(Math.random() * quotes.length); //select random quote
var newquote = quotes[ind].replace("(tjej1)", user1);
var quotediv = document.getElementById("quoteDiv"); //get the div (or any other element) that you want to display the quote in
quotediv.innerHTML = newquote; //display your quote in the div.
如何将input1(tjej1)中的值颜色更改为绿色而不是标准h3?我只希望值改变颜色:)
谢谢!
答案 0 :(得分:1)
var newquote = quotes[ind].replace("(tjej1)", '<span style="color:green">'+user1+'</span>');
答案 1 :(得分:0)
您可以通过CSS设置h3样式:
#quoteDiv{
color: green;
}
答案 2 :(得分:0)
Jquery keydown
$('#input').keydown(function(){
$(this).css('color','green');
});
Jquery keyup
$('#input').keyup(function(){
$(this).css('color','green');
});
Jquery改变
$('#input').chnage(function(){
$(this).css('color','green');
});