手机
当前位置:查字典教程网 >网页设计 >HTML5教程 >HTML 5 input placeholder 属性如何完美兼任ie
HTML 5 input placeholder 属性如何完美兼任ie
摘要:记得引用jquery类库$(document).ready(function(){if($.browser.msie)$("input:te...

记得引用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 + $id + "" + $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】相关文章:

HTML5如何实现元素拖拽

使用HTML5 和CSS3创建现代Web站点

HTML5 History API 实现无刷新跳转

HTML5里的placeholder属性使用实例和美化显示效果的方法

HTML5 visibilityState属性详细介绍和使用实例

HTML5 canvas基本绘图之绘制线段

HTML5的download属性详细介绍和使用实例

HTML5 自动聚焦(autofocus)属性使用介绍

HTML5 canvas 基本语法

HTML5 placeholder(空白提示)属性介绍

精品推荐
分类导航