IE8不支持html5 placeholder的解决方法。

/**
* jQuery EnPlaceholder plug
* version 1.0 2014.07.01戈志刚
* by Frans.Lee <dmon@foxmail.com> http://www.ifrans.cn
*/
(function ($) {
$.fn.extend({
"iePlaceholder":function (options) {
options = $.extend({
placeholderColor:'#999',
isUseSpan:true,
onInput:true
}, options); $(this).each(function () {
var _this = this;
var supportPlaceholder = 'placeholder' in document.createElement('input');
if (!supportPlaceholder) {
var defaultValue = $(_this).attr('placeholder');
var defaultColor = $(_this).css('color');
if (options.isUseSpan == false) {
$(_this).focus(function () {
var pattern = new RegExp("^" + defaultValue + "$|^$");
pattern.test($(_this).val()) && $(_this).val('').css('color', defaultColor);
}).blur(function () {
if ($(_this).val() == defaultValue) {
$(_this).css('color', defaultColor);
} else if ($(_this).val().length == 0) {
$(_this).val(defaultValue).css('color', options.placeholderColor)
}
}).trigger('blur');
} else {
var $imitate = $('<span class="wrap-placeholder" style="position:absolute; display:inline-block; overflow:hidden; color:'+options.placeholderColor+'; width:'+$(_this).width()+'px; height:'+$(_this).outerHeight()+'px;">' + (defaultValue==undefined?"":defaultValue) + '</span>');
//hg-add
$(_this).focus(function(){
$imitate.hide();
}).blur(function () {
/^$/.test($(_this).val()) && $imitate.show();
});
$imitate.css({
'margin-left':$(_this).css('margin-left'),
'margin-top':$(_this).css('margin-top'),
'text-align':'left',
'font-size':$(_this).css('font-size'),
'font-family':$(_this).css('font-family'),
'font-weight':$(_this).css('font-weight'),
'padding-left':parseInt($(_this).css('padding-left')) + 2 + 'px',
'line-height':_this.nodeName.toLowerCase() == 'textarea' ? $(_this).css('line-weight') : $(_this).outerHeight() + 'px',
'padding-top':_this.nodeName.toLowerCase() == 'textarea' ? parseInt($(_this).css('padding-top')) + 2 : 0
});
$(_this).before($imitate.click(function () {
$(_this).trigger('focus');
})); $(_this).val().length != 0 && $imitate.hide(); if (options.onInput) {
var inputChangeEvent = typeof(_this.oninput) == 'object' ? 'input' : 'propertychange';
$(_this).bind(inputChangeEvent, function () {
$imitate[0].style.display = $(_this).val().length != 0 ? 'none' : 'inline-block';
});
} else {
$(_this).focus(function () {
$imitate.hide();
}).blur(function () {
/^$/.test($(_this).val()) && $imitate.show();
});
}
}
}
});
return this;
}
});
})(jQuery); /*调用方式: textarea需要田间onInput=false属性*/
$('input[placeholder], textarea[placeholder]').each(function(){$(this).is('input')?$(this).iePlaceholder():$(this).iePlaceholder({onInput: false});}); $(document).ready(function(){
if (typeof (Worker) == "undefined"){
$('input[placeholder], textarea[placeholder]').each(function(){$(this).is('input')?$(this).iePlaceholder():$(this).iePlaceholder({onInput: false});});
} });

  测试html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--便于页面更好的在移动平台上展示。
<meta name="viewport" content="initial-scale=1.0,user-scalable=no">
-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Content-Language" content="utf-8" />
<meta name="author" content="Gezhigang" />
<title>placeholder</title> <script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="placeholder.js"></script> </head>
<body>
<div style="margin-left: 30%;margin-top: 10%;">
<form>
<table>
<tr>
<td height="30px">用户名</td>
<td><input type="text" placeholder="这里输入帐号。。。"/></td>
</tr>
<tr >
<td height="30px">密码</td>
<td><input type="text" placeholder="这里输入密码。。。"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="会员登录" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>

  测试例子

IE8 不支持html5 placeholder的解决方案的更多相关文章

  1. 如何让低版本的IE浏览器(IE6/IE7/IE8)支持HTML5 header等新标签

    html5提供的一些新标签(article,aside,dialog,footer,header,section,footer,nav,figure,menu)使用起来非常的方便,但是低版本的IE浏览 ...

  2. IE(IE6/IE7/IE8)支持HTML5标签

    让IE(ie6/ie7/ie8)支持HTML5元素,我们需要在HTML头部添加以下JavaScript,这是一个简单的document.createElement声明,利用条件注释针对IE来调用这个j ...

  3. IE(IE6/IE7/IE8)支持HTML5标签--20150216

    让IE(ie6/ie7/ie8)支持HTML5元素,我们需要在HTML头部添加以下JavaScript,这是一个简单的document.createElement声明,利用条件注释针对IE来调用这个j ...

  4. ie8及ie8以下支持html5 video标签

    html5media是一个很给力的JavaScript类库,它不依赖于任何JavaScript框架.使用了html5media之后,当浏览器不支持HTML5时,它将会自动切换成Flash模式的Flow ...

  5. js解决IE8不支持html5,css3的问题(respond.js 的使用注意)

    IE8.0及以下不支持html5,css3的解析.目前为止IE8以下的版本使用率在10%左右,网站还是有必要兼容的. 1,在你的所有css最后判断引入两个js文件. html5.js  是用来让ie8 ...

  6. 解决IE8不支持html5标签最好解决办法?

    完美解决IE(IE6/IE7/IE8)不兼容HTML5标签的方法:HTML5的语义化标签以及属性,可以让开发者非常方便地实现清晰的web页面布局,加上CSS3的效果渲染,快速建立丰富灵活的web页面显 ...

  7. 让 IE 支持HTML5 placeholder

    HTML5 新增的placeholder属性已经得到现代浏览器的支持,旨在提供简单的API可以为文本输入框设置 描述输入字段预期值的提示信息(hint). 这是W3C在标准化的过程中对用户体验的更多考 ...

  8. ie8如何支持html5

    两种方法 : 一:Coding JavaScript <!--[if lt IE9]> <script>    (function() {     if (!      /*@ ...

  9. 让IE6/IE7/IE8支持HTML5标签的js代码

    让IE(ie6/ie7/ie8)支持HTML5元素,我们需要在HTML头部添加以下JavaScript,这是一个简单的document.createElement声明,利用条件注释针对IE来调用这个j ...

随机推荐

  1. C基础--结构体

    C语言,结构体语法: 1.定义结构体类型: struct 结构体名称 { 成员类型 成员名称1; 成员类型 成员名称2; ... }; 例:struct Date { int year ; int m ...

  2. neutron中的dhcp功能

    1. 分布式dhcp 特点: 1)一个dhcp port对应多个host上的tap设备. 2)基于port event的network与agent的绑定与解绑定,即创建tap设备.namespace. ...

  3. JS模式:Mixin混合模式,=_=!就是常见的Object.create()或者_extend()

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. Emgu学习之(一)——Emgu介绍

    OpenCV“OpenCV是一个开源的计算机视觉库.OpenCV采用C/C++语言编写,可以运行在Linux/Windows/Mac等操作系统上.OpenCV还提供了Python.Ruby.MATLA ...

  5. 搭建的SSH 框架

    公用JDBC 方法,如果要保存数据,不许再service 中写,而且必须带save*  update* 的方法名才受事物控制,ajax 返回json 控制,登录拦截器, 用户体系我没有建立,个人需要不 ...

  6. PHP中GD2的运用,注意编码格式的改变,以及head()函数之前不能有任何html元素包括空格!!!

    <?php header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式 header("Cont ...

  7. linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg)

     linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg) 2013-11-10 16:51:14 分类: 系统运维 为什么要写这篇文章? 答:通过常规的三大步(./confi ...

  8. Java初学(五)

    一.成员变量和局部变量区别(成员变量默认为包内访问权限,即使是子类,不在一个包内也无法访问) 1.在类中的位置不同 成员变量:在类中方法外: 局部变量:在方法定义中或者方法声明上 2.在内存中的位置不 ...

  9. dedecms网站栏目增加缩略图的方法-测试通过

    有时候因为网站功能需求,我们需要为织梦程序的栏目页添加缩略图功能,这里有一个栏目添加缩略图的方法,供大家参考 涉及到文件如下(注意备份): dede/catalog_add.php dede/cata ...

  10. 设定所有tableView中cell的分隔线颜色

    上面只有针对xib或者storyboard中生成的tableview有效,如果想手码也有效,需在initwithframe中添加同样的方法