让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 ...
随机推荐
- 【BZOJ1968】【AHoi2005】COMMON约数研究
Description Input 只有一行一个整数 N(0 < N < 1000000). Output 只有一行输出,为整数M,即f(1)到f(N)的累加和. Sample Input ...
- WZJ的blog开通了
WZJ的blog开通了
- wxPython学习
http://www.cnblogs.com/coderzh/archive/2008/11/23/1339310.html 一个简单的实例: #!/usr/bin/python import wx ...
- upload控件上传json文件合并的两种方法
方法一: byte[] byte1 = FileUpload1.FileBytes; byte[] byte2 = FileUpload2.FileBytes; byte[] a1 = Encodin ...
- 兼容所有浏览器的设为首页收藏本站js代码
大家发现传统的收藏本站按钮在360浏览器下面没有效果了,但是360浏览器用户群却非常之大.所以我们在网上找到一个兼容所有浏览器的收藏本站解决方案,具体功能如下: 设为首页 和 收藏本站js代码 兼容I ...
- 将普通工程转为mvn标准工程(main resources)
It is sometimes required to change the default source folder working on the java project. One best e ...
- 在mapreduce中做分布式缓存的问题
一.问题描述: 主要解决一个问题,就是两个表做join,两个表都够大,单个表都无法装入内存. 怎么做呢?思路就是对做join的字段做排序两个表都排序,然后针对一个表a逐行读取,希望能够在内存中加载到另 ...
- 使用 GCC 调试程序
系统 Ubuntu 调试示例: #include <stdio.h> int func(int n) { ,i; ;i<n;i++) { sum+=i; } return sum; ...
- Eclipse上的项目分享到GitHub
1. 右击项目:team --> Share Project 2. 在弹出的选择框中选择 Git ,点击Next 3. Configure Git Repository 按照下图选择,点击Fin ...
- html中标签的含义及作用
链接:http://www.w3chtml.com/html/tag/div.html