HTML 5 input placeholder 屬性如何完美兼任ie
發(fā)布時間: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();
});
});
頁面調(diào)用
<input id="n1" type="text" placeholder="我是提示內(nèi)容正常" />
<input id="n2" type="text" placeholder="我是提示內(nèi)容寬高" style="width:100px;height:100px;" />
<input id="n3" type="text" placeholder="我是提示內(nèi)容我有其他樣式" / 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>
復(fù)制代碼
代碼如下:$(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();
});
});
頁面調(diào)用
復(fù)制代碼
代碼如下:<input id="n1" type="text" placeholder="我是提示內(nèi)容正常" />
<input id="n2" type="text" placeholder="我是提示內(nèi)容寬高" style="width:100px;height:100px;" />
<input id="n3" type="text" placeholder="我是提示內(nèi)容我有其他樣式" / style="width:300px;height:40px;font-weight:bold;">
<input id="n4" type="text" placeholder="還可以嘗試下其他的" />
樣式
復(fù)制代碼
代碼如下:<style type="text/css">
.placeholder {display:inline-block;color:gray;vertical-align:top;overflow:hidden;}
</style>
相關(guān)文章
詳解移動端HTML5頁面端去掉input輸入框的白色背景和邊框(兼容Android
本篇文章主要介紹了移動端HTML5頁面端去掉input輸入框的白色背景和邊框,非常具有實用價值,需要的朋友可以參考下。2016-12-15- HTML5改進的地方想必大家有所知曉,下面我要介紹的是兩個新的input元素類型email和url。讓我們跟著代碼來看看他們的好處,感興趣的朋友可以參考下2013-08-13
- 今天我剛接觸html+css3感覺還不錯,下面為大家介紹下用到的input 屬性,感興趣的朋友可以看下截圖哈,希望對大家有所幫助2013-06-28
- 這篇文章主要介紹了HTML5輸入框下拉菜單功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2020-09-08
html5實現(xiàn)輸入框fixed定位在屏幕最底部兼容性
這篇文章主要介紹了html5實現(xiàn)輸入框fixed定位在屏幕最底部兼容性,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小2020-07-03HTML5中input輸入框默認提示文字向左向右移動的示例代碼
這篇文章主要介紹了HTML5中input輸入框默認提示文字向左向右移動,本文通過實例代碼給大家介紹的非常詳細對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-10