HTML5inputplaceholder属性完美兼任ie的方法

这篇文章主要讲解了“HTML 5 input placeholder属性完美兼任ie的方法”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“HTML 5 input placeholder属性完美兼任ie的方法”吧!

创新互联建站主要从事网站建设、成都网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务杭州,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575

记得引用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="我是提示内容宽高"  />

<input id="n3" type="text" placeholder="我是提示内容我有其他样式" / >

<input id="n4" type="text" placeholder="还可以尝试下其他的" />


样式

代码如下:

<style type="text/css">
.placeholder {display:inline-block;color:gray;vertical-align:top;overflow:hidden;}
</style>

感谢各位的阅读,以上就是“HTML 5 input placeholder属性完美兼任ie的方法”的内容了,经过本文的学习后,相信大家对HTML 5 input placeholder属性完美兼任ie的方法这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!

网页题目:HTML5inputplaceholder属性完美兼任ie的方法
转载注明:https://www.cdcxhl.com/article12/igijdc.html

成都网站建设公司_创新互联,为您提供移动网站建设App设计外贸建站全网营销推广做网站网站策划

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都定制网站建设