让Placeholder在IE中燥起来
网上有好多关于这方面解决兼容性问题的文章,很多招式,学会这一招,让你轻松搞定Placeholder的兼容性,叫我好人,拿走,不谢。。。。
placeholder属性是HTML5 中为input添加的。在input上提供一个占位符,文字形式展示输入字段预期值的提示信息(hint),该字段会在输入为空时显示。
如
<input type="text" id="Title" class="so-input-d w270" placeholder="请输入标题" />
像下图用placeholder刚刚好,但是IE6 7 8 9 不支持呀,一篇空白!此时此刻心情肯定是日了狗!!!!!,搞web开发的一定要考虑兼容性,业界良心需要。。。。
使用前:

使用后:

疗效不一般,使用之后萌萌哒。
目前浏览器的支持情况:
| 浏览器 | IE6/7/8/9 | IE10+ | Firefox | Chrome | Safari |
| 是否支持 | NO | YES | YES | YES | YES |
下面分享一个Js文件代码,简单粗暴的把问题解决了:
(function ($) {
$.fn.myPlaceholder = function (options) {
var defaults = {
pColor: "#acacac",
pFont: "16px",
posL: 8,
zIndex: "99"
},
opts = $.extend(true, defaults, options);
if ("placeholder" in document.createElement("input")) return;
return this.each(function () {
//$(this).parent().css("position", "relative");
var isIE = $.browser.msie,
version = $.browser.version;
//不支持placeholder的浏览器
var $this = $(this),
msg = $this.attr("placeholder"),
iH = $this.outerHeight(),
iW = $this.outerWidth(),
iX = $this.offset().left,
iY = $this.offset().top,
oInput = $("<label>", {
"text": msg,
"css": {
"position": "absolute",
"left": iX + "px",
"top": iY + "px",
"width": iW - opts.posL + "px",
"padding-left": opts.posL + "px",
"height": iH + "px",
"line-height": iH + "px",
"color": opts.pColor,
"font-size": opts.pFont,
"z-index": opts.zIndex,
"cursor": "text"
}
}).insertBefore($this);
//初始状态就有内容
var value = $this.val();
if (value.length > 0) {
oInput.hide();
};
var myEvent;
if (isIE && version < 9) {
myEvent = "propertychange";
} else {
myEvent = "input";
}
$this.bind(myEvent, function () {
var value = $(this).val();
if (value.length > 0) {
oInput.hide();
} else {
oInput.show();
}
});
oInput.click(function () {
$this.trigger("focus");
});
});
}
})(jQuery);
这是用JQUERY插件化思想的解决的!
在页面或者操作的Js文件只用这样轻轻一搞:
$(function () {
$("#Title").myPlaceholder();
});
Placeholder兼容问题就解决了(文章标红的地方注意ID一致)!
抓紧有限的时间,燥起来!
让Placeholder在IE中燥起来的更多相关文章
- placeholder在IE8中兼容性问题解决
placeholder是HTML5中的一个属性,可以在文本框中设置placeholder属性来显示一些提示性的文字,但对IE10以下的浏览器不支持,下面方法可以让placeholder能够使用在IE1 ...
- 有关placeholder在ie9中的一点折腾
有关placeholder在ie9中的一点折腾. placeholder属性定义: placeholder 属性规定可描述输入字段预期值的简短的提示信息(比如:一个样本值或者预期格式的短描述). 问题 ...
- placeholder 解决UITextField中placeholder和text文本同时显示的问题
TextField都使用了placeholder属性,但在代码中又设置了text属性,因此ViewController会同时显示placeholder文本和text文本. 这个问题让我彻底崩溃.按道理 ...
- tf.placeholder类似函数中的形参
tf.placeholder(dtype, shape=None, name=None) 此函数可以理解为形参,用于定义过程,在执行的时候再赋具体的值 参数: dtype:数据类型.常用的是tf.fl ...
- ie8中使用placeholder
placeholder 是 html5 中的新属性,考虑到还有不少 ie8 的用户,所以找了一个 ie8 的 placeholder 的补丁,如下: <script type="tex ...
- cocos2dx 中使用的一些C++ 11 特性
0. placeholder 头文件:<functional> namespace: placeholder placeholder 就是一堆帮助bind占参数位置的东西,名字分别为 _ ...
- placeholder的兼容处理(jQuery下)
这是一个老问题,结合前辈们的经验,需要处理的问题有一下几个. 1.只有输入框(input/textarea)下的palaceholder属性存在的时候才需要处理这类兼容 2.处理好输入框上焦点和是焦点 ...
- DIV实现CSS 的placeholder效果
placeholder是HTML5中input的属性,但该属性并不支持除input以外的元素 但我们可以使用Css before选择器来实现完全相同的效果 <!DOCTYPE html> ...
- 兼容IE浏览器的placeholder【超不错】
jQuery EnPlaceholder plug (兼容IE浏览器的placeholder)使用 >>>>>>>>>>>>&g ...
随机推荐
- BZOJ 1012 题解
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8468 Solved: 3702[Submi ...
- js-小效果-瀑布流
<!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...
- 内存和flash存储的区别
http://bbs.21ic.com/icview-202550-1-1.html 一.内存 我们一般说的内存指的是DRAM,其主要特点是断电会丢失数据,可读写 二.ROM 断电不会丢失数据,数据只 ...
- 热烈庆祝华清远见成功自主研发Farsight TV 智能机顶盒
近日,华清远见研发中心再传喜讯:Farsight TV 智能机顶盒研发成功并投入教学!这是华清远见研发中心继开源平板电脑.智能医疗终端.智能家居终端后独立成功研发的又一智能硬件!至此,开创了华清远见自 ...
- 原创docker dcos 的安装
原创哈,上个星期无意间发现了一个可以好东西 DC/OS https://dcos.io 这个是官网哈 然后就痛苦的折磨了一个多星期; 基本是参照到https://dcos.io/docs/1.7/ad ...
- Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- 异常 java.util.regex.PatternSyntaxException:
可变参数是在JDK1.5之后出来的一个行特性,也是一个比较好用的东西 想起好多jfinal还有其他框架的查询方法就有好多用到了可变参数,自己也写了个这样的方法 public class Test{ ...
- Daily Scrum 10.26
虽然是星期六,大家也没有丝毫懈怠,但由于其他各科也已经布置了相应的大作业,我们组投入在软工作业上的时间也是有一定限度的.由于这次任务较重,今日的完成量只有一部分,剩余的留为明天继续. 下表是今日完成工 ...
- Graph | Eulerian path
In graph theory, a Eulerian trail (or Eulerian path) is a trail in a graph which visits every edge e ...
- Run P4 without P4factory - A Simple Example In Tutorials. -2
Reference:Github-Tutorial Exercise 2: Implementing TCP flowlet switching 实验准备: 参考之前的博客:Run P4 withou ...