让IE支持placeholder属性
来源:互联网 发布:部落冲突12本建筑数据 编辑:程序博客网 时间:2024/05/16 07:02
html 5 有个很棒的属性,placeholder,在鼠标聚焦到input输入框上面时候,提示文字会消失,失去焦点之后,又会出现:
但是在不支持html5的低版本的浏览器中,placeholder属性是无效的,为了解决这个问题,因此,人为的去实现placeholder属性:
/*
* jQuery placeholder, fix for IE6,7,8,9
* @author JENA
* @since 20131115.1504
* @website ishere.cn
*/
var
JPlaceHolder = {
//检测
_check :
function
(){
return
'placeholder'
in
document.createElement(
'input'
);
},
//初始化
init :
function
(){
if
(!
this
._check()){
this
.fix();
}
},
//修复
fix :
function
(){
jQuery(
':input[placeholder]'
).each(
function
(index, element) {
var
self = $(
this
), txt = self.attr(
'placeholder'
);
self.wrap($(
'<div></div>'
).css({position:
'relative'
, zoom:
'1'
, border:
'none'
, background:
'none'
, padding:
'none'
, margin:
'none'
}));
var
pos = self.position(), h = self.outerHeight(
true
), paddingleft = self.css(
'padding-left'
);
var
holder = $(
'<span></span>'
).text(txt).css({position:
'absolute'
, left:pos.left, top:pos.top, height:h, lienHeight:h, paddingLeft:paddingleft, color:
'#aaa'
}).appendTo(self.parent());
self.focusin(
function
(e) {
holder.hide();
}).focusout(
function
(e) {
if
(!self.val()){
holder.show();
}
});
holder.click(
function
(e) {
holder.hide();
self.focus();
});
});
}
};
//执行
jQuery(
function
(){
JPlaceHolder.init();
});
将上述JS引入页面中,inuput即可显示提示信息(兼容IE10以下)
0 0
- 让IE支持placeholder属性
- 让IE支持placeholder属性
- 让IE支持placeholder属性
- 让IE支持placeholder属性~
- 让IE支持placeholder属性
- 让IE支持placeholder属性,兼容IE6,7,8,9
- 兼容其他不支持placeholder的浏览器(超强的让IE下支持placeholder的属性插件)
- placeholder支持ie
- placeholder支持ie
- 让div支持placeholder属性/模拟输入框的placeholder属性
- 让所有浏览器都支持HTML5 placeholder属性
- 让低版本浏览器支持input的placeholder属性
- ie placeholder属性的兼容性问题
- 使IE兼容placeholder属性
- html5的placeholder属性(IE如何兼容placeholder属性)
- 让IE浏览器支持CSS3圆角属性的方法
- 让IE浏览器支持CSS3圆角属性的方法
- 让IE 6,7,8支持CSS3的部分属性
- GEOSQL插入数据 ArcGIS Desktop不显示的问题
- 辛星浅析linux下安装rails对于sqlite3缺少的问题
- CSDN网站系统升级公告
- (转)驱动开发之五 --- TDI之三 【译文】
- 利用dotm模板动态添加web报表数据
- 让IE支持placeholder属性
- 关于野指针的一些问题与总结
- iOS中关闭屏幕旋转功能时如何判断屏幕方向
- 【JQuery实例】---用户名验证
- DHCP的简介与配置
- (转)驱动开发之五 --- TDI之六 【译文】
- Android自定义控件之应用程序首页轮播图
- Android历史版本
- centos kvm配置