jQuery实现ie浏览器兼容placeholder效果
<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<title>jQuery实现IE浏览器兼容placeholder效果</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
} .input {
width: 200px;
height: 30px;
line-height: 30px;
padding: 0 10px;
border: 1px solid #ddd;
margin: 20px auto;
display: block;
}
</style>
</head> <body>
<input type="text" placeholder="请输入姓名" class="input" />
<script src="http://apps.bdimg.com/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() { //判断浏览器是否支持placeholder属性
supportPlaceholder = 'placeholder' in document.createElement('input'), placeholder = function(input) { var text = input.attr('placeholder'),
defaultValue = input.defaultValue; if (!defaultValue) { input.val(text).addClass("phcolor");
} input.focus(function() { if (input.val() == text) { $(this).val("");
}
}); input.blur(function() { if (input.val() == "") { $(this).val(text).addClass("phcolor");
}
}); //输入的字符不为灰色
input.keydown(function() { $(this).removeClass("phcolor");
});
}; //当浏览器不支持placeholder属性时,调用placeholder函数
if (!supportPlaceholder) { $('input').each(function() { text = $(this).attr("placeholder"); if ($(this).attr("type") == "text") { placeholder($(this));
}
});
} });
</script>
</body> </html>
效果图:
jQuery实现ie浏览器兼容placeholder效果的更多相关文章
- 【jquery】基于 jquery 实现 ie 浏览器兼容 placeholder 效果
placeholder 是 html5 新增加的属性,主要提供一种提示(hint),用于描述输入域所期待的值.该提示会在输入字段为空时显示,并会在字段获得焦点时消失.placeholder 属性适用于 ...
- 跨浏览器实现placeholder效果的jQuery插件
曾经遇到这样一个问题,处理IE8密码框placeholder属性兼容性.几经周折,这个方案是可以解决问题的. 1.jsp页面引入js插件 <script type="text/java ...
- jQuery 两种方法实现IE10以下浏览器的placeholder效果
/* ** jQuery版本:jQuery-1.8.3.min.js ** 测试的浏览器:IE8,IETester下的IE6-IE9** Author:博客园小dee */ placeholder是H ...
- ie兼容placeholder效果
转载:http://www.jb51.net/article/56244.htm placeholder是HTML5<input>的属性之一,在不同的浏览器( 支持HTML5的现代浏览器 ...
- Jquery ajaxSubmit()的浏览器兼容问题
form.ajaxSubmit({ 2 beforeSubmit: function() { 3 if (FinanceUtil.validate(form)) { 4 FinanceUtil.loa ...
- 低版本IE内核浏览器兼容placeholder属性解决办法
最简便的一个方法,通过js实现. <input type="text" name="username" id="username" v ...
- 兼容IE浏览器的placeholder【超不错】
jQuery EnPlaceholder plug (兼容IE浏览器的placeholder)使用 >>>>>>>>>>>>&g ...
- jQuery效果之封装模拟placeholder效果,让低版本浏览器也支持
页面中的输入框默认的提示文字一般使用placeholder属性就可以了,即: <input type="text" name="username" pla ...
- IE下支持文本框和密码框placeholder效果的JQuery插件
基于jQuery实现的,主要用于IE下实现placeholder效果,可同时支持文本和密码输入框.placeholder是HTML5新增的一个属性,当input设置了该属性后,该值的内容将作为灰色提示 ...
随机推荐
- AttributeUsage
[AttributeUsage] System.AttributeUsage声明一个Attribute的使用范围与使用原则. AllowMultiple 和 Inherited 参数是可选的,所以此代 ...
- 使用Cloudrea Manager在CDH集群中添加kafka服务节点,更改borker.id配置后无法启动
需要保证meta.properties文件中的broker.id和cloudrea manager的web页面上kafka配置的broker.id一致,最好让server.properties中的br ...
- 75. Sort Colors (Array)
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- c++ 备忘录模式(memento)
备忘录模式:在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态.这样以后就可将该对象恢复到原先保存的状态[DP].举个简单的例子,我们玩游戏时都会保存进度,所保存的进度以文件的 ...
- 深入理解mysql的隔离级别
建表插入测试数据A> create table test(id int ,num int) ;Query OK, 0 rows affected (0.53 sec) A> insert ...
- layer使用注意事项
ajax一定要设置为异步
- 一起做RGB-D SLAM (4)
第四讲 点云拼接 广告:“一起做”系列的代码网址:https://github.com/gaoxiang12/rgbd-slam-tutorial-gx 当博客更新时代码也会随着更新. SLAM技术交 ...
- CodeForces 342A Xenia and Divisors (水题)
题意:给定 n 个数(小于等于7),让你把它分成 m 组,每组有三个数,且满足,a < b < c,并且 a 能整除 b,b 能整除 c. 析:对于这个题,因为题目说了是不大于7的,那么一 ...
- CodeForces 474A Keyboard (水题)
题意:给定一个键盘,然后一行字母,和一个字符,代表把那一行字母在键盘上左移还是右移一位. 析:没什么好说的,直接暴力就好. 代码如下: #include<bits/stdc++.h> us ...
- mysql - 索引的一些理解
推荐下这篇文章 http://blog.codinglabs.org/articles/theory-of-mysql-index.html 写的十分的不错.留着以后慢慢看,慢慢的理解.