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. maven_创建quickstart模板时异常

    错误信息: Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:1.1 from an ...

  2. Java设计模式-桥接模式(Bridge)

    桥接模式就是把事物和其具体实现分开,使他们可以各自独立的变化.桥接的用意是:将抽象化与实现化解耦,使得二者可以独立变化,像我们常用的JDBC桥DriverManager一样,JDBC进行连接数据库的时 ...

  3. str和repr的

    尽管str(),repr()和``运算在特性和功能方面都非常相似,事实上repr()和``做的是完全一样的事情,它们返回的是一个对象的“官方”字符串表示,也就是说绝大多数情况下可以通过求值运算(使用内 ...

  4. 畅所欲言第1期 - 从Viola&Jones的人脸检测说起

    转载自http://c.blog.sina.com.cn/profile.php?blogid=ab0aa22c890006v0 不少人认识我或者听说我的名字都是因为我过去做的关于人脸检测的工作,那么 ...

  5. BZOJ-1951 古代猪文 (组合数取模Lucas+中国剩余定理+拓展欧几里得+快速幂)

    数论神题了吧算是 1951: [Sdoi2010]古代猪文 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1573 Solved: 650 [Submit ...

  6. 关于clonezilla

    Clonezilla 是一个很好的系统克隆工具,它可以说是吸取了 Norton Ghost 和 Partition Image 的优点.即不仅支持对整个系统进行克隆,而且也可以克隆单个的分区,这种灵活 ...

  7. HTTPS-能否避免流量劫持

    流量劫持是什么? EtherDream在一篇科普文章<>中详细介绍了流量劫持途径和方式. 流量劫持是一种古老的攻击方式,比如早已见惯的广告弹窗等,很多人已经对此麻木,并认为流量劫持不会造成 ...

  8. org.springframework.orm.hibernate3.LocalSessionFactoryBean的疑惑解决办法

    在项目中使用了SSH框架(Struts2 + Spring3+ Hibernate3),applicationContext中配置了sessionFactory <bean id="s ...

  9. IOS基础之 (十二) Block

    一 定义 Block封装了一段代码,可以在任何时候执行. Block可以作为函数参数或者函数的返回值,而其本身又可以带输入参数或返回值. 二 使用 1. 定义函数指针,然后在实现. #import & ...

  10. 操作haproxy配置文件教师版

    作用: 可查,可增,可删,可修改 #_*_coding:utf-8_*_ import os def file_handle(filename,backend_data,record_list=Non ...