从网上找的代码,自己封装了一下(前提:引用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. iOS textfield限制长度,中文占2字符,英文占1字符

    之前遇到一种情况,限制textfield长度,并且要适配多语言,做到,例如中文占2字符,英文占1字符,还有考虑其他语言,网上找了很多方法,不太合适,最后结合网上的方案,修改出了还比较适用. 首先,增加 ...

  2. jquery mouseout和mouseleave区别

    mouseout()和mouseleave() 都是鼠标移出元素时触发,但是这两者又有所区别,需要大家留意: 不论鼠标指针离开指定元素还是该元素子元素,都会触发 mouseout 事件. 只有在鼠标指 ...

  3. System.Speech.Synthesis 添加暂停、继续功能

    为了方便调用暂停.继续的方法.要将speech的功能写成一个类.直接附上代码: using System; using System.Collections.Generic; using System ...

  4. Xcode 中添加 .pch文件

    1  新建工程 2  创建  .pch文件 3   在setting里面进行设置:

  5. ARM编译空间属性(转)

    原文地址:http://www.cnblogs.com/hongzg1982/articles/2205093.html 1. 程序的空间属性 一般情况下,一个程序本质上都是由 bss段.data段. ...

  6. 高可用集群(HA)之Keeplived原理+配置过程

    原理--> 通过vrrp协议,定义虚拟路由,在多个服务节点上进行转移. 通过节点优先级,将初始虚拟路由到优先级高的节点上,checker工作进程检测到主节点出问题时,则降低此节点优先级,从而实现 ...

  7. php 去掉 头尾 空格 2种方法

    看似很简单的问题,其实还是有点坑的,首先这里 空格转义,不是字符串,直接用trim()是去不掉. 1,用preg_replace替换 $test = " dfadad 论责民与三英的关系77 ...

  8. php 中const和 define的区别

    在php中定义常量时,可用到const与define这两种方法,那他们到底有什么区别呢? 1.const用于类成员变量的定义,一经定义,不可修改.define不可用于类成员变量的定义,可用于全局常量. ...

  9. linq分组查询

    string[] arrStr = { ".com", "www.baidu.com", "www.qq.com", "www.b ...

  10. jQuery之动画效果

    1.show()显示效果 语法:show(speed,callback) Number/String,Function speend为动画执行时间,单位为毫秒.也可以为slow"," ...