js怎么改变input里value值的颜色

鼠标点击输入框 输入颜色是会变成黑色 这个怎么实现
我的代码在这 帮忙看下 改了好久都没实现
http://pan.baidu.com/s/1i3zhYbb

输入框得到焦点时,改变输入框中的文字颜色。

假设输入框的id是one:

$("#one").on('focus',function(){

$('#one').css('color','#000')

})

$("#one")表示定位到输入框,focus事件表示得到焦点状态。

css() 方法设置或返回被选元素的一个或多个样式属性。

设置指定的 CSS 属性的语法:

css("propertyname","value")。

扩展资料:

输入框其他状态:

1、输入框正在输入时:

$("#one").on('input',function(){ })  

input事件表示正在输入状态。

2、输入框失去焦点时

$("#ipt").on('blur',function(){})

设置多个 CSS 属性的语法:

css({"propertyname":"value","propertyname":"value",...});

举例:

$("p").css({"background-color":"yellow","font-size":"200%"});

温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2016-07-27
<style>
    body{margin:0px; padding:0px;}
    .body_center{width:900px; height:600px; margin:0 auto;}
    .logo{width:564px; height:55px; background:url(images/logo.png)}
    .top_right{width:210px; height:14px; float:right; margin-top:-19px;}
    .top_right em{display:inline-block;  width:16px; height:21px; background:url(images/r_2.gif) no-repeat; float:left;}
    .top_right a{font-size:13px; font-weight:bold; color:#999999; text-decoration:none; float:left;}
    .top_right a:hover{text-decoration:none; color:#f90; float:left;}
    .top_right2{width:100px; height:14px; margin-left:50px; float:right; margin-top:-19px;}
    .top_right2 em{display:inline-block;  width:16px; height:21px; background:url(images/r_2.gif) no-repeat; float:left;}
    .top_right2 a{font-size:13px; font-weight:bold; color:#999999; text-decoration:none; float:left;}
    .top_right2 a:hover{text-decoration:none; color:#f90; float:left;}
    .bg{width:900px; height:297px; background:url(images/bg.jpg) no-repeat; margin-top:12px;}
    .kmtext{width:493px; height:51px; float:left; margin:65px 200px;}
    .kmtext input{width:493px; height:51px; background:url(images/text.gif) no-repeat scroll left center transparent; color:#cccccc; font-size:30px; border:0 none; line-height:175%; padding-left:10px;}
    .kmtext2{width:493px; height:51px; float:left; margin:-60px 200px;}
    .kmtext2 input{width:493px; height:51px; background:url(images/text.gif) no-repeat scroll left center transparent; color:#cccccc; font-size:30px; border:0 none; line-height:175%; padding-left:10px;}
    .submit{border:0; width:132px; height:45px; background:url(images/tiqu.jpg) no-repeat; margin:0px 385px; float:left;}
    .prompt{background:#FF6600; width:300px; color:#FFFFFF; font-size:12px; margin:-45px 298px;}
    input:focus{color: #000;}/*在这里加上你想改变的*/
</style>

input:focus {

    border-color: #000;}

当input获得焦点的时候,改变颜色,你想改变border-color,或者字体颜色color,或者你想改变背景background-color

追问

怎么用了这个属性鼠标离开字又变回灰色了

追答

对的呀,谁获得焦点谁变黑,你指的是填写过后变黑的?可以用placeholder

本回答被提问者和网友采纳
第2个回答  推荐于2016-12-06
获取input这个元素,然后设置css中的color值就行,
比如:$('input[name=username]').css('color','purple');//设置成紫色文字
第3个回答  2015-08-21
$(input对象).css('color','你要的颜色');
相似回答