从网上找的代码,自己封装了一下(前提:引用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. asp.net断点续传技术---下载(转)

    断点续传的原理 在了解HTTP断点续传的原理之前,先来说说HTTP协议,HTTP协议是一种基于tcp的简单协议,分为请求和回复两种.请求协议是由客户机(浏览器)向服务器(WEB SERVER)提交请求 ...

  2. 使用安卓中的TextToSpeech控件实现朗读文字

    首先感谢原文的博主,本文中的代码均来自该博主:(原文地址)http://flycatdeng.iteye.com/blog/1827245 朗读文字不需要任何的权限,这个控件的好处是首先不要权限,其次 ...

  3. Eclipse闪退解决办法

    解决方式: 1.通过在命令行中输入“where java”,找到除jdk目录下的所有java相关程序,直接删掉(一般会在C:\WINDOWS\system32下) 2.内存不足,打开Eclipse目录 ...

  4. linux环境下编码的问题

    查看linux支持的编码格式: locale -a查看文件的编码格式: :set fileencodinglinux下文本编码转换: iconv -f gbk -t utf8 main.cpp > ...

  5. SSH连接LINUX乱码解决方法

    1.vi /etc/sysconfig/i18n 将内容改为 LANG="zh_CN.GB18030" LANGUAGE="zh_CN.GB18030:zh_CN.GB2 ...

  6. oracle 语句汇总

    Oracle数据库常用sql语句 ORACLE 常用的SQL语法和数据对象 一.数据控制语句 (DML) 部分 1.INSERT  (往数据表里插入记录的语句) INSERT INTO 表名(字段名1 ...

  7. Spring MVC中数据绑定(转)

    Spring MVC中数据绑定 比如Product有一个createTime属性,是java.util.Date类型.那么最简单的转型处理是,在SimpleFormController中覆盖initB ...

  8. iOS之本地推送(前台模式与后台模式)

    #import "AppDelegate.h" #import "GlobalDefine.h" @interface AppDelegate () @end ...

  9. SQL Server一些常见却不太记得住的命令

    一.数据库大小查询 1. exec sp_spaceused '表名'          --(SQL统计数据,大量事务操作后可能不准)2. exec sp_spaceused '表名', true  ...

  10. Python中的Copy和Deepcopy

    一,Python的对象: Python存在大量的对象,我们一般提到的对象都是C中的结构体在堆中申请的一块内存(以CPython为例),每一个对象都有ID,可以通过ID(Object)获得.对象的范围包 ...