HTML 5 input placeholder 属性如何完美兼任ie
发布时间:2014-05-12 11:27:22 作者:佚名 我要评论
这篇文章主要介绍了HTML 5 input placeholder 属性完美兼任ie的方法,需要的朋友可以参考下
记得引用jquery 类库
$(document).ready(function () {
if ($.browser.msie)
$("input:text,input:password").each(function () {
var $placeholder = $(this).attr("placeholder");
var $width = $(this).css("width");
var $id = $(this).attr("id");
var $height = parseInt($(this).css("height")) + 6 + "px";
var $fontSize = $(this).css("font-size");
var $fontWeight = $(this).css("font-weight");
var $lineHeight = $height;
if ($(this).css("line-height") != "normal") {
$lineHeight = parseInt($(this).css("line-height")) + 6 + "px";
}
if ($placeholder != undefined) {
$(this).after("<span class=\"placeholder ph_" + $id + "\" style=\"width:" + $width + ";line-height:" + $lineHeight + ";height:" + $height + ";font-weight:" + $fontWeight + ";margin-left:-" + $width + ";font-size:" + $fontSize + "\">" + $placeholder + "</span>");
}
$(this).bind("keyup", function () {
if ($(this).val() == "") {
$(this).parent().find(".ph_" + $id).css("display", "inline-block");
}
else {
$(this).parent().find(".ph_" + $id).css("display", "none");
}
});
});
$(".placeholder").live("click", function () {
$(this).prev().focus();
});
});
页面调用
<input id="n1" type="text" placeholder="我是提示内容正常" />
<input id="n2" type="text" placeholder="我是提示内容宽高" style="width:100px;height:100px;" />
<input id="n3" type="text" placeholder="我是提示内容我有其他样式" / style="width:300px;height:40px;font-weight:bold;">
<input id="n4" type="text" placeholder="还可以尝试下其他的" />
样式
<style type="text/css">
.placeholder {display:inline-block;color:gray;vertical-align:top;overflow:hidden;}
</style>
复制代码
代码如下:$(document).ready(function () {
if ($.browser.msie)
$("input:text,input:password").each(function () {
var $placeholder = $(this).attr("placeholder");
var $width = $(this).css("width");
var $id = $(this).attr("id");
var $height = parseInt($(this).css("height")) + 6 + "px";
var $fontSize = $(this).css("font-size");
var $fontWeight = $(this).css("font-weight");
var $lineHeight = $height;
if ($(this).css("line-height") != "normal") {
$lineHeight = parseInt($(this).css("line-height")) + 6 + "px";
}
if ($placeholder != undefined) {
$(this).after("<span class=\"placeholder ph_" + $id + "\" style=\"width:" + $width + ";line-height:" + $lineHeight + ";height:" + $height + ";font-weight:" + $fontWeight + ";margin-left:-" + $width + ";font-size:" + $fontSize + "\">" + $placeholder + "</span>");
}
$(this).bind("keyup", function () {
if ($(this).val() == "") {
$(this).parent().find(".ph_" + $id).css("display", "inline-block");
}
else {
$(this).parent().find(".ph_" + $id).css("display", "none");
}
});
});
$(".placeholder").live("click", function () {
$(this).prev().focus();
});
});
页面调用
复制代码
代码如下:<input id="n1" type="text" placeholder="我是提示内容正常" />
<input id="n2" type="text" placeholder="我是提示内容宽高" style="width:100px;height:100px;" />
<input id="n3" type="text" placeholder="我是提示内容我有其他样式" / style="width:300px;height:40px;font-weight:bold;">
<input id="n4" type="text" placeholder="还可以尝试下其他的" />
样式
复制代码
代码如下:<style type="text/css">
.placeholder {display:inline-block;color:gray;vertical-align:top;overflow:hidden;}
</style>
相关文章
详解移动端HTML5页面端去掉input输入框的白色背景和边框(兼容Android
本篇文章主要介绍了移动端HTML5页面端去掉input输入框的白色背景和边框,非常具有实用价值,需要的朋友可以参考下。2016-12-15- HTML5改进的地方想必大家有所知晓,下面我要介绍的是两个新的input元素类型email和url。让我们跟着代码来看看他们的好处,感兴趣的朋友可以参考下2013-08-13
- 今天我刚接触html+css3感觉还不错,下面为大家介绍下用到的input 属性,感兴趣的朋友可以看下截图哈,希望对大家有所帮助2013-06-28
- 这篇文章主要介绍了HTML5输入框下拉菜单功能,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧2020-09-08
- 这篇文章主要介绍了html5实现输入框fixed定位在屏幕最底部兼容性,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小2020-07-03
HTML5中input输入框默认提示文字向左向右移动的示例代码
这篇文章主要介绍了HTML5中input输入框默认提示文字向左向右移动,本文通过实例代码给大家介绍的非常详细对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-09-10
最新评论