码迷,mamicode.com
首页 > Web开发 > 详细

Input输入字体颜色改变js(兼容IE)

时间:2016-05-10 12:29:58      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

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

HTML:

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

javascript:

 1 function InputStyleChange(id,p,c1,c2){
 2 //函数
 3             var placeholder = p;
 4             var inputname = id;
 5             inputname.onfocus = function(){
 6                 if ( this.value == placeholder ) {
 7                     this.value = ‘‘;
 8                     this.style.color = c1;
 9                 }
10             };
11             inputname.onblur = function(){
12                 if (!this.value) {
13                     this.value = placeholder;
14                     this.style.color = c2;
15                 }
16             };
17 
18             if (inputname.value == placeholder) {
19                 inputname.style.color = c2;
20             }
21         }
22 
23 $(function){
24 InputStyleChange($(‘#tel‘)[0],‘phone‘,‘#323232‘,‘#b4b4b4‘);
25 //调用函数
26 //修改默认显示文字需要与Html表单默认文字对应
27 })

 

Input输入字体颜色改变js(兼容IE)

标签:

原文地址:http://www.cnblogs.com/mai0509/p/5477165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!