Input输入字体颜色改变js(兼容IE)
从网上找的代码,自己封装了一下(前提:引用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)的更多相关文章
- echarts x轴或y轴文本字体颜色改变
1:x轴文本字体颜色改变 xAxis : [ { type : 'category', data : ['<30','30-','40-','50-','60-','>=70'], axi ...
- jquery+css 实现即时变化颜色主题(通过input输入颜色值进行改变)
实现效果需要自行导入jquery.js <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
- android自定义控件实现TextView按下后字体颜色改变
今天跟大家分享一下Android自定义控件入门,先介绍一个简单的效果TextView,按下改变字体颜色,后期慢慢扩展更强大的功能 直接看图片 第一张是按下后截的图,功能很简单, ...
- 改变input光标颜色与输入字体颜色不同
设置input css: color #ffd600text-shadow 0px 0px 0px #bababa -webkit-text-fill-color initial input, tex ...
- 列表显示数据 但是数据的字体颜色要js添加
1.需求:数据在前台显示,但是每个条记录的颜色要有点不同 1.java后台数据的处理 String ids=""; for(int x=0;x<sign.size();x++ ...
- RadioGroup 的 RadioButton 选择改变字体颜色和背景颜色
RadioGroup <RadioGroup android:id="@+id/client_charge_radiogroup" android:layout_width= ...
- iOS改变UIAlertView、UIActionSheet、UIAlertController系统字体颜色
废话不多说,直接上代码,效果是最好的说服力 1.改变UIAlertView字体颜色 [UIView appearance].tintColor = [UIColor greenColor]; 个人还是 ...
- Android RadioGroup的RadioButton 选择改变字体颜色和背景颜色
RadioGroup <RadioGroup android:id="@+id/client_charge_radiogroup" android:layout_width= ...
- 改变input的placeholder字体颜色
改变input的placeholder字体颜色,注意哦,只是placeholder的字,用户输入的字不可以 input::-webkit-input-placeholder{ coloc:#000; ...
随机推荐
- MYSQL免安装版使用说明
1>把压缩文件mysql-noinstall-5.1.6-alpha-win32.zip解压到一个目录下,在环境变量中设置MYSQL_HOME,把%MYSQL_HOME%\bin 加入到 pat ...
- docker虚拟化之将容器做成镜像
1,docker ps -a 选择要启动的容器. 2,docker start 容器+ID 启动容器 3,docker exec -i -t 容器ID /bin/bash 进入容器 这里的/ ...
- openssl 对称加密算法enc命令详解
1.对称加密算法概述 openssl的加密算法库提供了丰富的对称加密算法,我们可以通过openssl提供的对称加密算法指令的方式使用,也可以通过调用openssl提供的API的方式使用. openss ...
- html中把li前面的的小圆点换成小图片的方法
li { list-style: none; background: url(../img/li_dis.png) no-repeat left; padding-left: 20px; }
- asp.net同时调用JS和后台的无效的解决
如果js是个定时器,那么就不走后台 <asp:Button runat="server" type="button" Text="重新发送邮件& ...
- alarm函数可以定时
貌似是可以的,不过感觉好像这样用不是很好,最好还是用回timer_settimer一些列函数吧,不过既然开了头,就看下alarm怎么用吧. 1. 所需头文件 #include<unistd.h ...
- java.lang.ClassNotFoundException: org.apache.struts.action.ActionServlet
- img元素高度多出来的几像素
HTML: <div class="test"><img src="body2.jpg" alt=""></d ...
- abiword Namespace List
abiword Namespace List Here is a list of all namespaces with brief descriptions: abicollab 这个命名空间以及 ...
- T-SQL 创建、修改、删除数据库,表语法
CREATE 语句 CREATE语句的开头都是一样的,然后是特定的细节. CREATE <object type> <object name> 一.CREATE DATABAS ...