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; ...
随机推荐
- sql语句中查询出的数据添加一列,并且添加默认值
查询出数据,并且要添加一列表中都不存在的数据,且这一列的值都是相等的 select app_id,app_secret from wx_ticket group by app_id; 查询出的数据是 ...
- sqlite3安装
SQLite命令行程序(CLP)是开始使用SQLite的最好选择,按照如下步骤获取CLP: 1).打开浏览器进入SQLite主页,www.sqlite.org. 2).单击页面顶部的下载链接(Down ...
- Android Eclipse Errors
1.The import org.apache.http.client; tip: cannot be resolved; resolve: Find library in your sdk and ...
- 利用PHP/MYSQL实现的简易微型博客(转)
数据库:ly_php_base 表:ly_micro_blog(仅仅有一个表)字段:id,title,date,content,hits 文件: 文件 描述 default.php 默认主页.显示博文 ...
- 如何在asp.net中如何在线播放各类视频文件
一.后台拼字符串动态加载写法 前台调用代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...
- (转) Friendship and inheritance
原地址: http://www.cplusplus.com/doc/tutorial/inheritance/ Friend functions In principle, private and p ...
- js常用设计模式
组合使用构造函数模式和原型模式.其中,构造函数模式用于定义实例属性,而原型模式用于定义方法和共享属性. 例子: <script> function Person(name,age,job) ...
- ZendFramework 环境部署
查看源码 int_autoloader.php 文件中,发现应用了一个 AutoloaderFactory 的命名空间,路径写得是相对路径,所以需要在 php.ini 中定义一个 inclde_pat ...
- python基础教程第4章——字典
1.映射(mapping):通过名字引用值的数据结构.字典是Python中唯一内建的映射类型,字典中的值并没有特殊的顺序,但是都存储在一个特定的键(key)里.键可以是数字.字符串甚至是元组. 2.字 ...
- python3.4+selenium爬58同城(一)
爬取http://bj.58.com/pbdn/0/pn2/中除转转.推广商品以外的产品信息,因为转转和推广的详情信息不规范,需要另外写一个方法存放,后期补上,详情页如下 这周学习了爬虫,但是遇到一些 ...