从网上找的代码,自己封装了一下(前提:引用jQuery库)

方法1:

HTML:

 <div class="box">
    <div  class="ipt1" ><input type="text" id="user" value="name" ></div>
    <div  class="ipt2" ><input type="text" id="tel" value="phone"></div>
    <input type="submit" class="submit" value="确   认">
</div>

javascript:

 function InputStyleChange(id,p,c1,c2){
 //函数
             var placeholder = p;
             var inputname = id;
            inputname.onfocus = function(){
                if ( this.value == placeholder ) {
                     this.value = '';
                    this.style.color = c1;
               }
             };
            inputname.onblur = function(){
                if (!this.value) {
                     this.value = placeholder;
                     this.style.color = c2;
                 }
            };

            if (inputname.value == placeholder) {
                inputname.style.color = c2;
             }
        }

 $(function){
 InputStyleChange($('#tel')[0],'phone','#323232','#b4b4b4');
//调用函数
 //修改默认显示文字需要与Html表单默认文字对应
 })

结语:经过测试火狐浏览器兼容存在问题。

 方法2:

html

<label>
    <input type="text" class="ipt pws"/></input>
    <span class="ph-label">密码</span>
</label>    

css

label{

    display: block;
    position: relative;

}

.ph-label{
    position: absolute;
    top: 0px;
    line-height: 52px;
    left: 1em;
    font-size: 12px;
    color: #a1a1a1
}

js

function InputStyleChange(inputs){
        inputs.each(function(i,e){
            $(e)[0].value="";//清空表单
            $(e).bind("focus",function(){
                $(e).siblings(".ph-label").hide();
            }).bind("blur",function(){
                if (!$(e).val()) $(e).siblings(".ph-label").show();
            }).siblings(".ph-label").click(function(element){
                $(element.target).hide();
                $(e).focus();
            })
        })
    }

InputStyleChange($('.ipt'));//调用函数

Input输入字体颜色改变js(兼容IE)的更多相关文章

  1. echarts x轴或y轴文本字体颜色改变

    1:x轴文本字体颜色改变 xAxis : [ { type : 'category', data : ['<30','30-','40-','50-','60-','>=70'], axi ...

  2. jquery+css 实现即时变化颜色主题(通过input输入颜色值进行改变)

    实现效果需要自行导入jquery.js <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  3. android自定义控件实现TextView按下后字体颜色改变

    今天跟大家分享一下Android自定义控件入门,先介绍一个简单的效果TextView,按下改变字体颜色,后期慢慢扩展更强大的功能 直接看图片             第一张是按下后截的图,功能很简单, ...

  4. 改变input光标颜色与输入字体颜色不同

    设置input css: color #ffd600text-shadow 0px 0px 0px #bababa -webkit-text-fill-color initial input, tex ...

  5. 列表显示数据 但是数据的字体颜色要js添加

    1.需求:数据在前台显示,但是每个条记录的颜色要有点不同 1.java后台数据的处理 String ids=""; for(int x=0;x<sign.size();x++ ...

  6. RadioGroup 的 RadioButton 选择改变字体颜色和背景颜色

    RadioGroup <RadioGroup android:id="@+id/client_charge_radiogroup" android:layout_width= ...

  7. iOS改变UIAlertView、UIActionSheet、UIAlertController系统字体颜色

    废话不多说,直接上代码,效果是最好的说服力 1.改变UIAlertView字体颜色 [UIView appearance].tintColor = [UIColor greenColor]; 个人还是 ...

  8. Android RadioGroup的RadioButton 选择改变字体颜色和背景颜色

    RadioGroup <RadioGroup android:id="@+id/client_charge_radiogroup" android:layout_width= ...

  9. 改变input的placeholder字体颜色

    改变input的placeholder字体颜色,注意哦,只是placeholder的字,用户输入的字不可以 input::-webkit-input-placeholder{ coloc:#000; ...

随机推荐

  1. HTML5+CSS3项目总结

      经过一个月的学习,我基本掌握了HTML5的一些标签的用法和特性,以及一些CSS3的属性的特点和用法. 在本周安排的为期四天的第一阶段的课程的项目实训中,我基本能够熟练运用学到的知识,完成页面的速度 ...

  2. javascript 之 this 用法

    参考视频:http://www.imooc.com/video/6430 JavaScript中的this比较灵活,也是让很多初学者摸不到头脑,那么根据在不同的环境下,在同一个函数,不同的调用方式下, ...

  3. 鼠标滚轮(mousewheel)和DOMMouseScroll事件

    IE6.0首先实现了mousewheel事件.此后,Opera.Chrome和Safari也都实现了这个事件.当用户通过鼠标滚轮与页面交互.在垂直方向上滚动页面时(无论向下还是向上),就会触发mous ...

  4. alarm函数可以定时

    貌似是可以的,不过感觉好像这样用不是很好,最好还是用回timer_settimer一些列函数吧,不过既然开了头,就看下alarm怎么用吧. 1. 所需头文件  #include<unistd.h ...

  5. Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.

    I have installed a Web application on IIS 7.0 windows server 2008 R2 64 bit OS I am refering a oracl ...

  6. canvas写的一个小时钟demo

    <!DOCTYPE html> <html> <head> <title>HTML5 Canvas Demo of clock</title> ...

  7. Unix is 命令

    输入正整数n以及n个文件名,排序后按列优先的方式左对齐输出.假设最长文件名有M字符,则最右列有M字符,其他列都是M+2字符. 附加条件每行最多输出60个字符,在此条件下要求行最少. Sample in ...

  8. JDK,TomCat安装配置

    JDK.Tomcat.myEclipse安装配置 准备安装包 JAVA运行环境包 JDK1.7下载地址: http://www.veryhuo.com/down/html/43205.html Jsp ...

  9. python-整理-vs2013新建文件编码

    使用VS2013新建py包和py空文件还有文本文件时发现编码是936.如果代码中写了中文关闭后再打开就乱码了. 找了几个小时,发现模板文件就是936编码,奇怪的是pyclass等其它模板是正常的UTF ...

  10. Pet(hdu 4707 BFS)

    Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...